Django ORM Model meta internal API to current API update

46 views
Skip to first unread message

Asif Saif Uddin

unread,
Aug 18, 2020, 10:45:11 AM8/18/20
to Django users

Hi,
I have got an old project of django 1.8 which use codes like

links = [rel.get_accessor_name() for rel in self._meta.get_all_related_objects()]

How would I upgrade this code snippets to django 2.2 LTS?

TIA

Mbah Victor

unread,
Aug 18, 2020, 5:42:09 PM8/18/20
to django...@googlegroups.com
I don't bro i just started new in Django

Victor

--
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/c408d424-7c94-43de-beae-4071d424e2ecn%40googlegroups.com.

Asif Saif Uddin

unread,
Sep 7, 2020, 10:53:20 PM9/7/20
to Django users
any help? I can share the full function

Shaheed Haque

unread,
Sep 8, 2020, 4:26:22 AM9/8/20
to django...@googlegroups.com
On Tue, 8 Sep 2020 at 03:54, Asif Saif Uddin <auv...@gmail.com> wrote:
any help? I can share the full function

I've poked around some of these dark corners, but only since the late 2.x series. After a bit of searching this find-the-field-that-connects-a-model-to-a-through-model and the linked
suggest these are/were private APIs and AFAIK, the best you can do is try to figure out what the old code was doing, and rework them using the likes of:
  • self._meta.related_objects
  • self._meta.fields_map
  • self._meta.local_many_to_man
and the other similarly named fields. One thing to note: if a field x points to a *set* of objects, you won't find a "self.x", but rather a "self.x_set" which must be followed using a query such as "self.x_set.all()" rather than a simple field dereference.

HTH, Shaheed

Reply all
Reply to author
Forward
0 new messages