Re: Modifying Model Field Attributes on Run Time

2007-07-18 Thread Malcolm Tredinnick

On Wed, 2007-07-18 at 17:08 +, Sebastian Macias wrote:
> Is there anyway to modify model field attributes on run time.. What
> I'm trying to do is to build some logic that will decide whether a
> model that is related to other model should be edited or not inline in
> the admin.
> 
> Basically: "client = models.ForeignKey(Client, unique=True,
> edit_inline = True, core=True)" should be changed to client =
> models.ForeignKey(Client, unique=True, edit_inline = False) on run
> time.

It should be possible, if you're careful (entirely unsupported, though,
so if it breaks you get to keep both pieces). After a model class has
been parsed at import time, all the information about the Field classes
resides in the _meta attribute, which is an Options class from
django/db/models/options.py. The fields themselves are all subclasses of
Field, which is in django/db/models/fields/__init__.py. Both of those
files are fairly well documented in the comments, so it should be fairly
straightforward to read through the Field class (as a starting point) to
work out what you need to change.

Regards,
Malcolm

-- 
Quantum mechanics: the dreams stuff is made of. 
http://www.pointy-stick.com/blog/


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Modifying Model Field Attributes on Run Time

2007-07-18 Thread Sebastian Macias

Is there anyway to modify model field attributes on run time.. What
I'm trying to do is to build some logic that will decide whether a
model that is related to other model should be edited or not inline in
the admin.

Basically: "client = models.ForeignKey(Client, unique=True,
edit_inline = True, core=True)" should be changed to client =
models.ForeignKey(Client, unique=True, edit_inline = False) on run
time.


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---