Custom field specified by model with the full application label problem

Showing 1-8 of 8 messages
Custom field specified by model with the full application label problem Frank Becker 4/17/12 2:58 AM
Hi,

I'm trying to "southify" the app django-podcasting[0]. In it's models it
references django-licenses [1] custom field licences.fields.LicenseField
(which is derived from ForeignKey).

Here is the code of that custom field.

   def __init__(self, **kwargs):
       kwargs.setdefault('verbose_name', _('license'))
       if kwargs.pop('required', None) == False:
           kwargs['blank'] = True
           kwargs['null'] = True
->      ForeignKey.__init__(self, 'licenses.License', **kwargs)

The problem is the 'licenses.License' to: field as you'll see in a sec.
The Django documentation describes that here:
https://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.ForeignKey

So, I wrote a rule:

from south.modelsinspector import add_introspection_rules

licence_introspection_rule = (
   (LicenseField,),
   [],
       {
       #'to': ['rel.to', {'default': 'licenses.License'}],
       'to': ('rel.to',  {'default': License}),
       },
   )

add_introspection_rules(
   [licence_introspection_rule], ["^licenses\.fields\.LicenseField"])

While migrating I get an exception:
 File "/[...]python2.7/site-packages/django/db/models/fields/related.py",
line 861, in get_related_field
   data = self.to._meta.get_field_by_name(self.field_name)
AttributeError: 'str' object has no attribute '_meta'

So the problem is that South seems not to resolve the str
'licenses.License'. Am I wrong?
How to work around that?

Changing the custom field in django-licenses to
        from licenses.models import License
        ForeignKey.__init__(self, License, **kwargs)
works just fine.

[0] https://github.com/rizumu/django-podcasting
[1] https://bitbucket.org/jezdez/django-licenses/

Thanks,

    Frank

Re: Custom field specified by model with the full application label problem Andrew Godwin 4/17/12 3:00 AM

South does attempt to do this - the error can occur, though, if the
licenses application is not frozen in the migration along with the
field. Does the generated migration file have a 'licenses.license' entry
in the big dict at the bottom?

Andrew

Re: Custom field specified by model with the full application label problem Frank Becker 4/17/12 3:20 AM
Hi,

thanks a lot for your prompt answer.

I just pushed that file to github. Please have a look yourself.
https://github.com/a8/django-podcasting/commit/a24ede325398f1d44d5e507d5126e0da875de0e3
I am not 100% sure which dict you mean. Somewhere in the middle there is an entry
in the models dict.

Thanks for helping out!

Frank

--
Frank Becker

> --
> You received this message because you are subscribed to the Google Groups "South Users" group.
> To post to this group, send email to south...@googlegroups.com (mailto:south...@googlegroups.com).
> To unsubscribe from this group, send email to south-users...@googlegroups.com (mailto:south-users+unsubscribe@googlegroups.com).
> For more options, visit this group at http://groups.google.com/group/south-users?hl=en.

Re: Custom field specified by model with the full application label problem Andrew Godwin 4/17/12 3:39 AM
On 17/04/12 11:20, Frank Becker wrote:
> Hi,
>
> thanks a lot for your prompt answer.
>
> I just pushed that file to github. Please have a look yourself.
> https://github.com/a8/django-podcasting/commit/a24ede325398f1d44d5e507d5126e0da875de0e3
> I am not 100% sure which dict you mean. Somewhere in the middle there is an entry
> in the models dict.

Hmm, it looks fine to me there. I'm afraid I don't see what the problem
is (provided you're running the latest South - we've had this issue a
couple of times before but fixed it).

If you can reduce it to a simple test case (i.e. two models in a simple
app), then I'd suggest filing a bug report with that.

Andrew

Re: Custom field specified by model with the full application label problem Frank Becker 4/17/12 3:42 AM

On Tuesday, 17. April 2012 at 12:39, Andrew Godwin wrote:

> On 17/04/12 11:20, Frank Becker wrote:


Hi again,

OK, I'll try that. South is 0.7.4, Django 1.4.

Thanks,

Frank
 

Re: Custom field specified by model with the full application label problem Frank Becker 4/17/12 6:06 AM
On Tuesday, 17. April 2012 at 12:42, Frank Becker wrote:
> > >
> > > I just pushed that file to github. Please have a look yourself.
> > > https://github.com/a8/django-podcasting/commit/a24ede325398f1d44d5e507d5126e0da875de0e3
> > > I am not 100% sure which dict you mean. Somewhere in the middle there is an entry
> > > in the models dict.
> >
> >
> >
> >
> >
> > Hmm, it looks fine to me there. I'm afraid I don't see what the problem
> > is (provided you're running the latest South - we've had this issue a
> > couple of times before but fixed it).
> >
> > If you can reduce it to a simple test case (i.e. two models in a simple
> > app), then I'd suggest filing a bug report with that.
>
>
>
> OK, I'll try that. South is 0.7.4, Django 1.4.
All right here it is:
https://bitbucket.org/alien8/north/

The ticket is here: http://south.aeracode.org/ticket/1066

 
Thanks again,

Frank

Re: Custom field specified by model with the full application label problem Frank Becker 4/23/12 8:14 AM
Hi,

Can you verify that as a bug or did I do something wrong? Can I do anything to help on this issue?

Thanks,

Frank

--
Frank Becker

Re: Custom field specified by model with the full application label problem Andrew Godwin 4/23/12 8:20 AM
On 23/04/12 16:14, Frank Becker wrote:
> Hi,
>
> Can you verify that as a bug or did I do something wrong? Can I do anything to help on this issue?

Hi Frank,

I haven't had a chance to investigate this yet, and might not do for
another week or so, I'm afraid. I recommend you just stick with a direct
import for now.

Andrew