Re: Separating models from proxies conflicts

16 views
Skip to first unread message

cs

unread,
Sep 13, 2012, 11:19:27 AM9/13/12
to django...@googlegroups.com


Am Montag, 20. August 2012 15:52:28 UTC+2 schrieb Nacho Mas:
I'm trying to separate my models from my proxies in order to maintain the functionality more easily. The point is that, as my models.py started to grow over and over, I decided to create a new file in each app (proxies.py) where I'd define my proxies. I used to work like this:
# models.py
class MyModel(models.Model):
    prop1
= ...
    prop2
= ...

   
def f1(self):
       
pass
   
def f2(self):
       
pass

However, I wanted to have this structure:
# models.py

class MyModel(models.Model):
    prop1
= ...
    prop2
= ...

# proxies.py

from myapp import models


class MyModel(models.MyModel):

   
def f1(self):
       
pass
   
def f2(self):
       
pass

   
class Meta:
        proxy
= True
But, when I tried to make some tests:
$ python manage.py shell
Python 2.7.3 (default, Apr 20 2012, 22:44:07)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from myapp.proxies import MyModel
>>> MyModel
<class 'MyProject.myapp.models.MyModel'>
So, when I ask for the proxy it gives me the model in models.py. And, of course, it keeps the properties defined on the model but lacks all of the methods in the proxy. Could anybody please tell me WTF is going on here?
Thanks for your help :)

you probably want this:

# models.py

class MyModelBase(models.Model):
prop1 = ...
prop2 = ...

# proxies.py

from myapp import models


class MyModel(models.MyModelBase):

def f1(self):
pass
def f2(self):
pass

class Meta:
proxy = True

$ python manage.py shell

from myapp.proxies import MyModel
m = MyModel()
m.f1()
m.f2()

Reply all
Reply to author
Forward
0 new messages