title: How to make a readonly field that can not be edited by user in a Django forms?
body: <p>I'm trying to create my first own project in python django. What I'v done so far is a simple shop.
  When I click this:</p>
  
  <p>item_details.html</p>
  
  <pre><code>&lt;a href="{% url 'buy_item' pk=item.pk %}" class="submit"&gt;Kup teraz&lt;/a&gt;
  </code></pre>
  
  <p>I will be redirected</p>
  
  <p><b>urls.py</b></p>
  
  <pre class="lang-py prettyprint-override"><code>path('buy/&lt;int:pk&gt;', ItemCreate.as_view(), name='buy_item')
  </code></pre>
  
  <p>To this form:</p>
  
  <p><b>form.py</b></p>
  
  <pre class="lang-py prettyprint-override"><code>class BuyForm(forms.ModelForm):
  
      class Meta:
          model = Order
          fields = (
          'item',
          'delivery',
          'price',
          'buyer',)
  </code></pre>
  
  <p>With this view:</p>
  
  <p><b>views.py</b></p>
  
  <pre class="lang-py prettyprint-override"><code>class ItemCreate(CreateView):
      model = Order
      fields = ['item', 'price', 'buyer', 'delivery']
  
      def get_initial(self):
          item = get_object_or_404(Item, pk=self.kwargs['pk'])
          self.initial.update({
              'buyer': self.request.user,
              'price': item.price,
              'item': item.pk,
          })
          return super(ItemCreate, self).get_initial()
  </code></pre>
  
  <p><b>models.py</b></p>
  
  <pre><code>from django.db import models
  from django.utils import timezone
  from django.contrib.auth.models import User
  
  class Category(models.Model):
      title = models.CharField(max_length=100)
      description = models.TextField()
  
      def __str__(self):
          return self.title
  class Item(models.Model):
      seller = models.ForeignKey(User, on_delete=models.CASCADE)
      category = models.ForeignKey(Category, on_delete=models.CASCADE)
      title = models.CharField(max_length=100)
      price = models.FloatField(null=False, blank=False)
      img = models.ImageField(blank=True, null=True,
          upload_to='covers/%Y/%m/%D/')
      published_date = models.DateTimeField(default=timezone.now)
      def __str__(self):
          return self.title
  
  class Supplier(models.Model):
      title = models.CharField(max_length=100)
      def __str__(self):
          return self.title
  
  class Delivery(models.Model):
      title = models.ForeignKey(Supplier, on_delete=models.CASCADE)
      price_of_delivery = models.FloatField(null=False, blank=False)
      def __str__(self):
          return self.title
  
  class Order(models.Model):
      item = models.ForeignKey(Item, on_delete=models.CASCADE)
      delivery = models.ForeignKey(Delivery, on_delete=models.CASCADE)
      order_date = models.DateTimeField(default=timezone.now)
      buyer = models.ForeignKey(User, on_delete=models.CASCADE)
      price = models.FloatField(null=False, blank=False)
      def __str__(self):
          return self.item
  </code></pre>
  
  <p>Because the initial data shouldn't be edited by user, I'd like to make them readonly.</p>
  
  <p>What I've tried so far is:</p>
  
  <pre><code>class BuyForm(forms.ModelForm):
  
      def __init__(self, *args, **kwargs):
         super(BuyForm, self).__init__(*args, **kwargs)
         self.fields['buyer'].widget.attrs['readonly'] = True    
  
      class Meta:
          model = Order
          fields = (
          'item',
          'delivery',
          'price',
          'buyer',)
  </code></pre>
  
  <p>No errors in my console but also there's no results. </p>
  
  <p>My order_form.html looks that:</p>
  
  <pre><code>{% extends 'shop/base.html' %}
  {% block content %}
  
  &lt;div align="center"&gt;
      &lt;h1&gt;Buy item&lt;/h1&gt;
      &lt;form method="POST" class="post-form"&gt;{% csrf_token %}
          {{ form.as_p }}
          &lt;button type="submit" class="save btn btn-default"&gt;Buy&lt;/button&gt;
      &lt;/form&gt;
  &lt;/div&gt;
  &lt;
  {% endblock %}
  </code></pre>
  
  <p>What should I do to make "buyer", "price" and the "item" readonly?</p>