Wednesday, November 26, 2014

Re: metaclass on model class calling db.models.options method vs django 1.7

Hi,

I feel like there's almost always a way to avoid metaclasses.

Have you tried adding your relations in the app.ready() signal?

For more context, could you post some of your metaclass code and maybe part of a "AppRegsitryNotReady" traceback or two?

Also, get_field_by_name(name)[0] will be deprecated soon. Use .get_field(name) instead.

Collin


On Tuesday, November 25, 2014 7:05:54 AM UTC-5, Matthieu Rigal wrote:
Hi guys,

I am using a metaclass to standardize how I link two classes, on Django 1.6. This is done in order to have a generic way of connecting classes without having to know the name of the fields being linked.

Basically, I have in my metaclass 'post_new' method to get the 'other' model, using model._meta.get_field_by_name('item') I use this afterward like following add_lazy_relation(model, None, item_model, add_passthrough_fields) 

I add these PassThrough fields again getting the fields from the meta, overwriting the getter and the setter.

Upgrading to Django 1.7 is impossible with what I'm currently doing. I get tons of AppRegistryNotReady , since it is going through this post_new method at the very beginning. 

Maybe you have a suggestion how I could get around this or which other methods to call to call later (but not too late, those are metaclasses) in order to get the list of fields. Maybe some code snippets running on Django 1.7 and using models with metaclasses could already help.

Thanks in advance,
Matthieu

PS: I know it is a bit uncommon to do so and if you don't need to do so and use these metaclasses, you shouldn't ;-)

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/62dde61e-a247-43b1-b594-1345d01a34c7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment