django - python classes that refer to each other -


I have two classes that show each other, but clearly the compiler complains. Is there a way around it?

Edit

Actually my code is slightly different than using hunk. Therefore, Python can certainly deal with some types of circular references, but it tells about an error in the following situation. The following is what I have found and I get a 'name wi not defined error'.

class X (models.model): creator.register () creator.register (Y ) Class Y (Models.Model): a = Model Firenci (X) B = Model.Carfild (max_length = 200)

Hope it helps to clarify. Any suggestions

In class, the class is loaded when class is loaded.

Now, what does this mean? ; -)

Consider the following code:

  class x: print "hello" def __init __ (self): print "hello again"  

When you load the module that contains the code, the dragon will print Hello whenever you create x , the dragon will print again Hello .

You can think of def __init __ (self): ... as __init__ = lambda self: ... Equally, none of the Python Lambda restrictions is applicable.

is an assignment, which can explain why the methods are not outside the code but the methods inside have not run.

When your code says

  Class.x (models.Model): Manufacturer = Registry () creator.register (Y)  
< P> You refer to y when the module is loaded, before y is a value, you can enter class X as an assignment. (But I can not remember the syntax for closing anonymous classes; Maybe it's an invitation for type ?)

What do you want to do Can:

  square X (Models.Model): Close class Y (models.Model): foo = something_that_uses_ (X) X.bar = Some_which_uses (Y)  

That is, X y after y is created> or vice versa: y first, then X , then the properties of y which are dependent on X , if it is easy.

Hope this helps :)


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -