Categories
Mastering Development

Django ‘Query’ object has no attribute ‘contains_column_references’

I am new in Django and i am having trouble on how to configure this error, so that is why i decided to post a question of some of my code, i hope you guys help me on this problem. did i miss or i did wrong in my code? please bear with me. thanks. […]

Categories
Mastering Development

Django – How to query a list inside of a filter method

I am new to Django and I want to query a list inside of an object. I have a list of Batches and each batch has a BatchComment list. Both of them has a User property. What I want to do is get batches where user has a comment and only get ones where the […]

Categories
Mastering Development

Custom Django SlugField Validation Breaks URL Matching

I wrote a custom field validator for slugs in my URLs (accepting periods in slugs for one model, SLUG_REGEX = ‘[-a-zA-Z0-9_.]+$’): def validate_my_slug(value): my_slug_re = re.compile(settings.SLUG_REGEX) if not my_slug_re.match(value): raise ValidationError( _(‘Slugs must consist of letters, numbers, ‘ ‘underscores, hyphens, or periods.’), params={‘value’: value}, ) The field in models.py: slug = models.CharField(max_length=64, null=True, blank=True, validators=[validate_my_slug]) […]

Categories
Mastering Development

Django ForeignKeyField assign one field with only one another field

I’m trying to create model TravelAgentDocumentType which consists of two ForeignKey’s i.e travel_agent and document_type the plan is to have one travel agent can have only one document type, below is my models class TravelAgentDocument(BaseModel): travel_agent = models.ForeignKey(TravelAgent, null=True, on_delete=models.CASCADE) document_type = models.ForeignKey( DocumentType, on_delete=models.SET_NULL, null=True ) TravelAgent model is class TravelAgent(BaseModel): name = models.CharField( […]

Categories
Mastering Development

QuerySet django . How to write a function correctly to make tests pass

how returns in tree_downwards the root organization with the requested org_id and all its children at any nesting level and returns in tree_upwords the root organization with the requested org_id and all its parents at any nesting level to make tests pas??? I will only be able to return either the parents or the organization […]

Categories
Mastering Development

django how to create instance of user

I am creating a simple application, successfully created for a single user, but I want to develop for multiple users, but unable to do so… i.e. user A can create his task and save in the database. similar B user can create tasks and store in the database. and each can see their own tasks […]

Categories
Mastering Development

Not getting the URL of Update api in DJANGO

Creating an api for create schedule for doctor,through which doctor will feed his whole week timings.That will work on update. I am trying to create update api ,using primary key,but i am not getting the url of update api in postman.If i changes to create then i am getting the url. Some one do guide […]

Categories
Mastering Development

Django forms: how to get product’s data from db with ajax

I have models (ShopStock and SaleItem), I have registered product and price in ShopStock model, in SaleItem model i also have product and price fields. What i want is when i select a product in (SaleItemForm) the price field to be filled with a price from Shopstock model. I have no idea how to do […]

Categories
Mastering Development

Django Serializer getting attribute from another model

I am working just for my experience and I stacked with the following problem. There are three models: Book, Chapter, and Publisher. Each model is related to one another with the foreign key. class Book(models.Model): name = models.CharField(max_length=64) publisher = models.ForeignKey(‘Publisher’, on_delete=models.CASCADE, null=True, blank=True) def __str__(self): return self.name class Chapter(models.Model): name = models.CharField(max_length=128) book = […]

Categories
Mastering Development

Easiest way to add from different related model in one template

I got a question. I’m wondering what’s the easiest way to add different from different related model in one template. I’d like to add some information related to seller rating: def total_seller_ratings(self): return self.seller.rating_seller.count() def avg_seller_ratings(self): return self.seller.annotate(avg_ratesugar=Avg(‘rating_seller__ratesugar’)).order_by(‘-avg_ratesugar’) Create a template tag from Middleware? Or is any fastes solution to add another model on my […]