I have my models reviews and news, both having a manytomany relation with Category model. Now I want to get all the categories associated with only one of these two models. For example, to get all categories associated with News model, I tried querying database with News.categories.all() but got AttributeError: ‘ManyToManyDescriptor’ object has no attribute ‘objects’. News Model: Reviews Model:
Tag: django-queryset
Splitting dictionary objects
I am building a Blog App and I made a queryset which is showing blog date and likes of every day since blog date, But it is showing in dictionary and i am trying to show both instances differently in table like. Blog Date Likes 20 Sep. 6 Likes 21 Sep. 2 Likes 22 Sep. 4 Likes But it is
How to remove the querysets ‘< [ (code markers?)’ for html (Django)
Am trying to just get a list of the made up gigs, (and hopefully make them links, to view them in a different html). Page result right now looks like this; <QuerySet [<Gig: Fulltime assistent needed from fall 2021!>, <Gig: Looking for event staff!>]> I don’t know how to remove queryset ‘code markers(or what are they called?)’. Just want the
How to filter based on referencing values? django
My model My goal is to get values that greater or equal the max or less than or equal the min. But, how to reference the max or min value from inside MyCell.objects.filter Answer You can compare your MyCell.Value and MyColumn.max with F() expressions.
django custom Func for specific SQL function
I’m currently performing a raw query in my database because i use the MySQL function instr. I would like to translate is into a django Func class.I’ve spend several days reading the docs, Django custom for complex Func (sql function) and Annotate SQL Function to Django ORM Queryset `FUNC` / `AGGREGATE` but i still fail to write succesfully my custom
About converting custom functions in models into annotations in custom managers/querysets
Being new to Django, I’m starting to care a bit about performance of my web application. I’m trying to transform many of my custom functions / properties which were originally in my models to querysets within custom managers. in my model I have: But I’m not clear on a few points: 1/ is there any pros or cons declaring with
Getting the current date (and time) in Django
I was wondering what is the best way to get the current date in a django application. Currently I query the python datetime module – but since I need the date all over the place I thought maybe Django already has a buildin function for that. e.g. I want to filter objects created in the current year so I would
How to use Query Strings for filtering Querysets in Django?
I created my “API” using REST framework, now I am trying to do filtering for it. This is how my models.py looks like: I would like to see “all passengers in particular workspace” or “all passengers in particular airline” etc in my JSON file. Here is my serializers.py: And views.py: I would like to use Filtering against query parameter but
Django-queryset join without foreignkey
model.py What I want is to get id_noga where dzienrok=1234. I know that dziens should be but it isn’t and I can’t change that. Normally I would use something like but I don’t know how to join and filter those tables without foreignkey. Answer It’s possible to join two tables by performing a raw sql query. But for this case
sql “LIKE” equivalent in django query
What is the equivalent of this SQL statement in django? How do I implement this in django? I tried But that did not work. How do i implement this? Answer Use __contains or __icontains (case-insensitive): The SQL equivalent is @Dmitri’s answer below covers patterns like ‘pattern%’ or ‘%pattern’