I've not and I'm not sure how or where to do that.

On Wednesday, August 5, 2015 at 4:38:36 PM UTC-5, James Bennett wrote:
>
> Have you tried setting "required=False" in your custom field override?
>
> On Wed, Aug 5, 2015 at 3:23 PM, Scott Gibson <scott....@hp.com 
> <javascript:>> wrote:
>
>> The django admin app is requiring a foreign key to be populated even 
>> though the model is defined and migrated with null=true and blank=true.
>>
>> What I've found is that the admin app will treat the field as required if 
>> the associated AdminForm(forms.ModelForm) overrides the fields collection 
>> for the foreign key field.
>>
>> e.g. the init for the admin class has something like this in it:
>>
>> self.fields['FKFIELD'] = 
>> ContextNameChoiceField(queryset=FKMODEL.objects.all())
>>
>>
>>
>> For reference ContextNameChoiceField is sub class of ModelChoiceField 
>> which is handling a specific call to get a user friendly list of choice 
>> values.
>>
>> If the self.fields* line is commented out the field is no longer required 
>> but now the values to choose from aren't friendly. To explain friendly.. 
>> the FK is to the bottom of a hierarchical structure. e.g. 
>> Region/Country/Site where Site is the FK relate but the same Site name can 
>> exist in multiple countries so Site name alone isn't unique. The 
>> ContextNameChoiceField class produces a site name that includes the 
>> region/country/site to aide the selection of the correct site.  It's done 
>> this way to allow for a single assignment versus a 3 FK assignment using 
>>  region, country, site individually.
>>
>>
>> My guess is that the admin class init override is clearing some settings 
>> for the FKField that would normally come from the model.  I'm not sure how 
>> to look into what's happening on object construction to verify though.
>>
>>
>>
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com <javascript:>.
>> To post to this group, send email to django...@googlegroups.com 
>> <javascript:>.
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/1664e67a-efc5-4dc1-a688-c23864b88e28%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/1664e67a-efc5-4dc1-a688-c23864b88e28%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d91eb894-2e15-44cd-943b-dcd3dd3609c0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to