add_inrospection_rules for field having callable with args as value for field attribute

56 views
Skip to first unread message

Marconius Cuthemustard

unread,
May 25, 2012, 10:30:00 PM5/25/12
to south...@googlegroups.com

My project uses South and I want to use django-private-files fields for some of my apps. private_files does not provide introspection rules, so I wrote some in my app's fields.py file. Usually theses are pretty straight forward, but I never had to write rules for a custom field that has an attribute who's value is a callable with arguments. This is what I got:

# myapp/models.py
from django.db import models
import fields # to add south introspection rules
from private_files import PrivateFileField

class Image(models.Model):
    description
= models.CharField("description", max_length = 200)
    image
= PrivateFileField("image file", upload_to = 'uploads')

-

# myapp/fields.py
from private_files import PrivateFileField
"""
South introspection rules
"""


from south.modelsinspector import add_introspection_rules
rules
= [
   
(
       
(PrivateFileField,),
       
[],
       
{
           
"condition": ["condition", {}],
           
"attachment" : ["attachment", {"default": True}],
       
},
   
)]

add_introspection_rules
(
    rules
,
   
["^private_files\.models\.fields\.PrivateFileField"])

These rules are for the PrivateFileField

When I run ./manage.py schemamigration --initial myapp I get TypeError: is_user_authenticated() takes exactly 2 arguments (0 given), which makes sense as South calls all callable values without args.

Can anyone help me write these introspection rules? Maybe I can tell South can ignore this argument?

Thanks in advance for your help.

P.S: This question was also asked on stackoverflow.

Andrew Godwin

unread,
May 26, 2012, 5:28:00 AM5/26/12
to south...@googlegroups.com
On 26/05/12 03:30, Marconius Cuthemustard wrote:
> My project uses South and I want to use django-private-files
> <https://bitbucket.org/vvangelovski/django-private-files/src> fields for
> <https://bitbucket.org/vvangelovski/django-private-files/src/f2cfbbb3b878/private_files/models/fields.py#cl-36>
>
> When I run |./manage.py schemamigration --initial myapp| I get
> |TypeError: is_user_authenticated() takes exactly 2 arguments (0 given),
> which makes sense as South calls all callable values without args.
> |
>
> Can anyone help me write these introspection rules? Maybe I can tell
> South can ignore this argument?

Yes, that's the only solution - South's introspection system isn't
designed for a second level of call-ability.

If you just omit the rule for the argument in question, South will
ignore it, as long as you have an overall call to
add_introspection_rules saying the field is OK. You don't make it clear
which is the problem field in your example, but assuming it's
"condition", this new snippet would work as you want:

> from south.modelsinspector import add_introspection_rules
> rules = [
> (
> (PrivateFileField,),
> [],
> {
> "attachment" : ["attachment", {"default": True}],
> },
> )]
>
> add_introspection_rules(
> rules,
> ["^private_files\.models\.fields\.PrivateFileField"])

Andrew

Marconius Cuthemustard

unread,
May 28, 2012, 2:57:05 PM5/28/12
to south...@googlegroups.com
it is indeed the `condition` argument. thanks for your help
Reply all
Reply to author
Forward
0 new messages