OK, I've tried the proxy models and they solved part of my problems.
But not all.

Consider I have an auto-generated model called COmpany which I have
manually (and can then make it automatically) renamed to CompanyAuto.
I have created the Company proxy model for the CompanyAuto model and
added the __unicode__ method. Then I have registered the (new proxy)
Company model in admin and can use __unicode__ attribute as list item,
for example.

But when it comes to Many-to-One self-relations...
The Company(Auto) has the 'self'-referencing 'branch_of' attribute.
'self'==CompanyAuto, so in the company editing form I have the combo-
box containing dozens of 'CompanyAuto object' entries.
I tried to manually changed 'self' to 'Company' reference (I put the
Company definition in the same models.py file where moved the auto-
generated models), but it has no effect.

On Oct 7, 5:04 pm, Eugene Mirotin <emiro...@gmail.com> wrote:
> I have tried it earlier and (as far as I remember) with the same
> (void) result.
> I have read more docs and proxy models seem to be the solution to my
> problem. I will give them a try later today.
>
> On Oct 7, 2:54 pm, greatlemer <greatle...@googlemail.com> wrote:
>
> > What sort of errors are you getting when you try this with the django
> > model?
>
> > Have you tried just assigning the function over the top of the
> > __unicode__ function already on Company?
>
> > i.e.
>
> > import Company
>
> > def CompanyUnicode(self):
> >     return '%s [%s]' % (self.nick, self.legal_name)
>
> > Company.__unicode__ = CompanyUnicode
>
> > __
>
> > G
>
> > On Oct 7, 12:07 pm, Eugene Mirotin <emiro...@gmail.com> wrote:
>
> > > Let me provide more details.
>
> > > When I make simple python project with the same idea, everything works
> > > fine.
>
> > > # file test2.py
> > > class A:
> > >     b = 2
> > > # file test1.py
> > > from test2 import *
>
> > > class A(A):
> > >         a = 1
> > > # file test.py
> > > from test1 import *
>
> > > a = A()
> > > print a.b, a.a
>
> > > print A.__module__
>
> > > The output is
> > > 2 1
> > > test1
>
> > > So class A is imported from test2 to test1, then overloaded (actually
> > > extended) there, then imported to test, cool.
>
> > > When I do the same in django, everything goes wrong.
>
> > > I do import models_auto in models_business_logic, then overload the
> > > Company class, then import it in models, then import models in admin
> > > file and try
> > > print Company.__module__
> > > And this gives me the dbadm.models_auto output
>
> > > On Oct 6, 4:10 pm, Eugene Mirotin <emiro...@gmail.com> wrote:
>
> > > > We have an existing app written in perl with Postgre as DB.
> > > > I want to add the django admin as the interface to this existing DB.
> > > > The main app is in constant development, so the DB scheme may change
> > > > in the future.
> > > > I have checked the inspectdb output and it is quite good (I do also do
> > > > some automatic fixing of the results of inspectdb, but these fixes are
> > > > minor).
> > > > So, if we would only want to have the 'dumb' db editing tool, the
> > > > auto-generated models are OK.
> > > > But what we really want is adding some additional logic (such as
> > > > __unicode__ representations and save validations). Of course, it is
> > > > unacceptable to have this code in the auto-generated file, not is is
> > > > good to always manually insert it after every db scheme update (the
> > > > models file generated by inspectdb is 1000+ lines long).
>
> > > > What I have tried looked like
> > > > - have the models_auto.py file - the inspectdb patched output
> > > > - have the models_business_logic.py module looking like
>
> > > > from models_auto import *
>
> > > > Company_ = Company
> > > > del Company
>
> > > > class Company(Company_):
> > > >     def __unicode__(self):
> > > >         return '%s [%s]' % (self.nick, self.legal_name)
>
> > > > - have the models.py file simpli importing * from models_business_logic
>
> > > > But dues to inheritance mechanism and Foreign keys (or may be dues to
> > > > some other reasons) this approach do not work.
> > > > Any ideas?
>
> > > > Thanks in advance.
>
>
--~--~---------~--~----~------------~-------~--~----~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to