Question

I am not sure if this is a bug, by design or if I have done something wrong. I have run into this on 1.6.2 and 1.6.4

I have some fields in my models like:

my_custom_field = models.CharField()

In my forms.py, I have:

def clean_my_custom_field():

It does not get called. There seems to be a problem with having more than one underscore in the field name. I have several that have 2 or 3 underscores in the name. I have changed one to use a single underscore and it worked.

I have started to look at shortening the names, but was wondering if anyone has come across this and has a work around/fix. Would be nice to keep the descriptive names.

Or is it in fact a bug?

UPDATED:

The form is setup fairly basic. One thing to note is that the long field name seems to work in the Admin, but not in the front end form.

class MyBaseForm(forms.ModelForm):
    class Meta:
        model = MyModel
        fields = "__all__"

    def clean_active_listing_expiry_date(self):
        print "You are HERE!"
        "Do something else here"

UPDATE:

class MyModel(models.Model):
    ... other fields listed before and after of course.
    active_listing_expiry_date = models.DateTimeField(
        verbose_name='Active Expiry Date',
        help_text="Date format: YYYY-MM-DD",
        blank=True,
        null=True
    )

UPDATE:

views.py

def residential_add(request, ptype='Residential', template_name='properties/add_residential.html'):
    if request.method == 'POST':
        property_form = ResidentialPropertyForm(request.POST)

        if property_form.is_valid():
            print "*" * 60
            print "FORM IS VALID"

    else:
        property_form = ResidentialPropertyForm()

    return render_to_response(
        template_name,
        {
            'property': property_form,
        },
        context_instance=RequestContext(request)
    )
Was it helpful?

Solution

Unfortunately I wasn't able to reproduce the problem on a fresh install as suggested by @schillingt so I decided to start the form, view and validation code from scratch. Not sure what was missed the first time around, but at this point the issue seems to be resolved.

Thanks to those that offered up their help.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top