Hi Alex, On 02/11/2015 11:39 AM, Alexander Hill wrote: > I'm looking for some background about abstract models, specifically why > they aren't registered with the app registry as normal models are. > > For some context, I'm working on a ticket [0] to refactor Django's lazy > model operations (used e.g. to resolve string references in related > fields). To acquire an actual model class from an "app_label.ModelName" > string, we use Apps.get_registered_model. However, as far as that method > is concerned, abstract models don't exist, so operations that wait on > them are never run. > > It also means abstract models clutter the pending operations dict, > making it impossible to provide a good warning when there's a typo in a > string model reference, for example. > > Fortunately this doesn't matter too much in practise, because concrete > subclasses work fine despite related fields not being hooked up right on > an abstract parent. > > [0] https://code.djangoproject.com/ticket/24215
Django treats abstract models as simply a convenient way to group some fields and Python-level behavior; they aren't real models in any sense (they have no db table, you can't query on them, you can't get them from the app registry, etc.) It sounds like the behavior you're describing is mostly consistent with that, except for the "clutter the pending operations dict" part. I would think that ideally abstract models should never appear in the pending operations dict at all in the first place, and any warning regarding a typo in a string model reference should be fired based on a concrete subclass, not based on the abstract base itself. Is there a problem with that approach? (It's been a long time since I looked at that code in detail.) Carl -- You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/django-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/54DBA429.1070804%40oddbird.net. For more options, visit https://groups.google.com/d/optout.
signature.asc
Description: OpenPGP digital signature
