Django hide field when creating new object
<p>I want to hide field name when user is creating new object, but it must be visible if user wants to edit this object. 
I tried exclude method but it makes field invisible when i try to edit this field. for example i want to hide status field.</p>

<pre><code>class Toys(BaseModel):
    name = models.CharField(max_length=255)
    tags = models.ManyToManyField(Tag, related_name='Item_tags')
    price = models.CharField(max_length=255)
    status = models.BooleanField(default=False)
</code></pre>

<p>In the model admin that you register in your <code>admin.py</code> file you can overload the <code>get_form(self, request, obj=None, **kwargs)</code> method. As you can see it takes the obj argument, it is <code>None</code> only on add (not <code>None</code> on change).
From there you could mess around with the form to exclude the form field "name" from it only if the <code>obj is None</code>.</p>

<p>In Django 1.10 that method is in <code>django.contrib.admin.options.ModelAdmin.get_form</code>.</p>

<p><strong>EDIT 1</strong> (<strong>this is by far not the best solution</strong>)
I can't give you a full solution here, but you can start with something like: </p>

<pre><code># admin.py

from django.contrib import admin

from models import Toys


class ToysModelAdmin(admin.ModelAdmin):

    def get_form(self, request, obj=None, **kwargs):
        # all the code you have in the original
        # django.contrib.admin.options.ModelAdmin.get_form
        # up to the last try except

        if obj is not None:
            defaults['fields'] = ('tags', 'price', 'status', )

        try:
            return modelform_factory(self.model, **defaults)
        except FieldError as e:
            raise FieldError(
                '%s. Check fields/fieldsets/exclude attributes of class %s.'
                % (e, self.__class__.__name__)
            )

admin.site.register(Toys, ToysModelAdmin)
</code></pre>

<p><strong>EDIT 2</strong> (<strong>this is a better example</strong>)</p>

<pre><code># admin.py

from collections import OrderedDict

from django.contrib import admin

from models import Toys


class ToysModelAdmin(admin.ModelAdmin):

    # this is not perfect as you'll need to keep track of your
    # model changes also here, but you won't accidentally add
    # a field that is not supposed to be editable
    _add_fields = ('tags', 'price', 'status', )

    def get_form(self, request, obj=None, **kwargs):
        model_form = super(ToysModelAdmin, self).get_form(
            request, obj, **kwargs
        )

        if obj is None:
            model_form._meta.fields = self._add_fields
            model_form.base_fields = OrderedDict(**[
                (field, model_form.base_fields[field])
                for field in self._add_fields
            ])

        return model_form
</code></pre>

python django