Gee, sorry about my bad wording of the problem, I think I tried
importing the models from a different application, however when I try
to do the variable asignment to a ForeignKey Model it does not take
the Model.


I import the models:

import rocola_erp.fact_rocola.models

I create the class with the variable impuesto making reference to a
model that is in the fact_rocola app

class producto (models.Model):
        idprod = models.AutoField(primary_key=True)
        nombre = models.CharField(max_length = 30,
verbose_name="Nombre de producto")
        marca = models.ForeignKey(marca)
        categoria = models.ForeignKey(categoria)
        descripcion = models.CharField(max_length=250)
        existencia = models.DecimalField(max_digits=19, decimal_places=2)
        cantidad_maxima = models.DecimalField(max_digits=19, decimal_places=0)
        cantidad_minima = models.DecimalField(max_digits=19, decimal_places=0)
        codigo = models.CharField(max_length=30)
        precio_minimo = models.DecimalField(max_digits=19, decimal_places=2)
        precio_descuento = models.DecimalField(max_digits=19, decimal_places=2)
        precio_normal = models.DecimalField(max_digits=19, decimal_places=2)
        impuesto = models.ForeignKey(rocola_erp.fact_rocola.models.Impuesto)
        imagenproduco = models.ImageField(upload_to='imagenes/',
verbose_name="Imagen de producto")
        def __unicode__(self):
                return self.nombre
        class Admin:
                pass


[EMAIL PROTECTED]:~/workspace/urbe_rocola/rocola_erp$ python manage.py syncdb
Traceback (most recent call last):
  File "manage.py", line 11, in <module>
    execute_manager(settings)
  File "/usr/lib/python2.5/site-packages/django/core/management/__init__.py",
line 340, in execute_manager
    utility.execute()
  File "/usr/lib/python2.5/site-packages/django/core/management/__init__.py",
line 295, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/lib/python2.5/site-packages/django/core/management/base.py",
line 77, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/lib/python2.5/site-packages/django/core/management/base.py",
line 95, in execute
    self.validate()
  File "/usr/lib/python2.5/site-packages/django/core/management/base.py",
line 122, in validate
    num_errors = get_validation_errors(s, app)
  File "/usr/lib/python2.5/site-packages/django/core/management/validation.py",
line 28, in get_validation_errors
    for (app_name, error) in get_app_errors().items():
  File "/usr/lib/python2.5/site-packages/django/db/models/loading.py",
line 128, in get_app_errors
    self._populate()
  File "/usr/lib/python2.5/site-packages/django/db/models/loading.py",
line 57, in _populate
    self.load_app(app_name, True)
  File "/usr/lib/python2.5/site-packages/django/db/models/loading.py",
line 72, in load_app
    mod = __import__(app_name, {}, {}, ['models'])
  File 
"/home/evalles/workspace/urbe_rocola/rocola_erp/../rocola_erp/fact_rocola/models.py",
line 3, in <module>
    from rocola_erp.inventario.models import producto
  File 
"/home/evalles/workspace/urbe_rocola/rocola_erp/../rocola_erp/inventario/models.py",
line 21, in <module>
    class producto (models.Model):
  File 
"/home/evalles/workspace/urbe_rocola/rocola_erp/../rocola_erp/inventario/models.py",
line 34, in producto
    impuesto = models.ForeignKey(rocola_erp.fact_rocola.models.Impuesto)
AttributeError: 'module' object has no attribute 'models'




On Sat, Sep 27, 2008 at 1:02 PM, bruno desthuilliers
<[EMAIL PROTECTED]> wrote:
>
> On 26 sep, 17:53, "Efrain Valles" <[EMAIL PROTECTED]> wrote:
>> I have been trying to reference a model from another application I
>> wrote for the same project.  basically what I need to do is asign a
>> relationship between two model classes  in different apps.
>>
>> example
>>
>> module Product has a model class that belongs to the inventory app and
>> the tax field of Product should use the tax module from the Billing
>> app.
>>
>> I tried a simple import
>>
>> from myproject.app1.models import tax
>
> You'd better use:
>
> from app1.models import Tax
>
> hints :
> - use CamelCase for classes
> - if app1 is in the same project, then you don't need to reference
> your project package
> - else, you'll have to add app1 to your pythonpath anyway
> - in both cases, you don't want to mention the project package itself
> - else it will break if you rename the 'myproject' directory, or try
> to reuse both apps in another project.
>
> Reading Python's FineManual(tm), specially the section about modules,
> packages and imports (in the tutorial) might be a good idea.
>
>> and then I:
>>
>> tax = models.ManyToManyField(tax)
>
> The results of this statement is that the name 'tax' is rebound to the
> models.ManyToManyField, sus shadowing the binding to the imported
> 'tax' class in the current class namespace. This may (or not) be the
> cause of your problem.
>
> You may want to search comp.lang.python's archive for posts about name
> bindings and namespaces in Python.
>
>> but it does nto work
>
> I can only second Steve's remark on this : "does not work" is almost
> the worst possible description of a problem.  The useful thing to do
> is to:
>
> 1/ post minimal working code exhibiting the problem.
> 2/ explain clearly what you expected
> 3/ explain clearly what you got instead. If an exception is raised,
> please post the *whole* traceback.
>
>
> HTH
> >
>

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

Reply via email to