Get queryset outside models.py

16 views
Skip to first unread message

Ezequias Rocha

unread,
Aug 23, 2019, 4:49:22 PM8/23/19
to Django users
Hi everyone

I would like to know if it is possible to retrieve models.mymodel instance from outside the models.py to retrieve a queryset.

I want to make a selection in a specific model but I am not inside the model.

I need to perform some update in my action  model but the information is in another entity.

I tryed to use Manager (mymodel = models.Manager() but I havn't found any function to get an specific queryset from Manager.

Could someone help me with this issue?

Best regards
Ezequias

Sipum

unread,
Aug 23, 2019, 8:29:04 PM8/23/19
to django...@googlegroups.com
What error you are getting cannu post it here with your code for model manager. 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/2aa7bdd8-3f4e-4949-beed-292468e8edaf%40googlegroups.com.

James Schneider

unread,
Aug 24, 2019, 1:20:54 AM8/24/19
to django...@googlegroups.com

I would like to know if it is possible to retrieve models.mymodel instance from outside the models.py to retrieve a queryset.

Yes, a vast majority of the time you'll be retrieving instances from your views and templates. There are only a few cases where you would retrieve instances within models.py.


I want to make a selection in a specific model but I am not inside the model.

In almost all cases you will NOT be inside of the code for the model when pulling instances from the database.


I need to perform some update in my action  model but the information is in another entity.

I tryed to use Manager (mymodel = models.Manager() but I havn't found any function to get an specific queryset from Manager.

Could someone help me with this issue?

Without the specific code you are using, I can't comment on what issue you are having, however, the one line you provided doesn't appear to follow the convention if you are replacing the default model manager. More information can be found here:




However, given the other questions you are asking, I doubt you have need for a custom model manager at this stage. I have a feeling you are implementing it simply to address other built-in functionality you want that you may not be aware of how to access. I could be wrong, though.

I'd recommend running through the official tutorial, as that covers the information to answer your questions and broaden your understanding in some detail.





-James
Reply all
Reply to author
Forward
0 new messages