0

In django admin page, One mobile has 10 indexes associated with it as listed in lst. Index should be readonly field. index field should auto increment each time if I repeat mobile number in forms. For new mobile number index should start from 1. form wont accept new entry if I repeat mobile eleventh time. Please help me on this. I am very new to django. Thanks in advance.

from django.db import models
from django.core.validators import MaxLengthValidator

from django.db import models


class Customer(models.Model):

        lst = [(1, 'one'), (2, 'two'), (3, 'three'), (4, 'four'), (5, 'five'), (6,'six'), (7, 'seven'), (8, 'eight'),
           (9, 'nine'), (10, 'ten')]
        name = models.CharField(max_length=50, default='ABC')
        address = models.CharField(max_length=80, default='ABC')
        id = models.PositiveIntegerField(default='0000', primary_key=True)
        mobile = models.IntegerField(default='0')
        index = models.PositiveIntegerField(choices=lst, default=lst[0])

        def __str__(self):  # __unicode__ on Python 2
        return "%s" % self.name
DomTomCat
  • 8,189
  • 1
  • 49
  • 64
Rajat
  • 1
  • 1
  • what is your question? – e4c5 Jun 04 '16 at 09:22
  • As e4c5 has asked the question here is still not clear. However you can make a field readonly by defining custom ModelAdmin and adding index as readonly_fields. You can read about it here https://docs.djangoproject.com/en/1.9/ref/contrib/admin/#django.contrib.admin.ModelAdmin.readonly_fields Also you can override the save method to increment index for reference use http://stackoverflow.com/questions/4269605/django-override-save-for-model – mascot6699 Jun 04 '16 at 11:18
  • It is like, I can use one mobile number for 10 customer entries only, and index field gives number how many times i have used it as I go on adding entries.(it should not be mandatory to add the same mobile number for **consecutive** 10 customer entries). Hope this will help you understand better.. – Rajat Jun 04 '16 at 18:56
  • Please somebody help me on this.. I still did not find any solution..... In above example, if 'mobile' is entered, it should search in database for entered mobile number and occurrences count should be displayed on index field. Also index value should not exceed beyond 10. That is it will accept same mobile number only 10 times. – Rajat Jun 11 '16 at 14:08

0 Answers0