Re: How to use class_prepared signal

2008-10-16 Thread Malcolm Tredinnick


On Thu, 2008-10-16 at 16:11 +0200, Thomas Guettler wrote:
> Hi,
> 
> I try to use the class_prepared signal to register permissions on a
> model class.
> 
> Example: MyModel has a View-Permission. To avoid typos I don't want
> to use the string representation of permissions ('myapp_view_mymodel').
> 
> I want to use a class attribute (MyModel.PERM_VIEW) in my code.
> 
> It seems like a chicken-egg problem: If the class_prepared gets called,
> I can't import the model class, since it is not ready:
>   ImportError: cannot import name MyModel.
> 
> If I try to write the code into models.py, I can't create a new db with
> syncdb, since the table itself and the entry in the permission table
> is not done yet.
> 
>  Any suggestions?

Don't make it a class attribute. Just put it in a separate file that
both the models and the signal handler can import. Pretty much every
circular dependency problem is solved in this way: making finer-grained
separations so that the really common stuff that only depends on itself
can be pulled out and the other pieces don't have to depend on each
other, just on the common stuff.

Regards,
Malcolm



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



How to use class_prepared signal

2008-10-16 Thread Thomas Guettler

Hi,

I try to use the class_prepared signal to register permissions on a
model class.

Example: MyModel has a View-Permission. To avoid typos I don't want
to use the string representation of permissions ('myapp_view_mymodel').

I want to use a class attribute (MyModel.PERM_VIEW) in my code.

It seems like a chicken-egg problem: If the class_prepared gets called,
I can't import the model class, since it is not ready:
  ImportError: cannot import name MyModel.

If I try to write the code into models.py, I can't create a new db with
syncdb, since the table itself and the entry in the permission table
is not done yet.

 Any suggestions?

  Thomas


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---