I'm trying to set custom id for my model,

*models.py*

from django.db import models
import uuid


def get_ref_id():
 ref_id = str(uuid.uuid4())[:11].replace('-','').lower()
 try:
 id_exists = Sample.objecsts.get(ref_id = ref_id)
 get_ref_id()
 except:
 return ref_id


class Sample(models.Model):
 ref_id = models.CharField(max_length = 128, primary_key = True, default=
get_ref_id)
 email = models.EmailField(max_length=128,unique=True)


 def __unicode__(self):
 return self.email


class MobileNumber(models.Model):
 sample = models.ForeignKey(Sample)
 mobile_number = models.CharField(max_length=128)


*admin.py*
















*from django.contrib import adminfrom sample.models import Sample, 
MobileNumberclass MobileNumberInline(admin.StackedInline): model = 
MobileNumber extra = 1class SampleAdmin(admin.ModelAdmin): inlines = 
[MobileNumberInline]admin.site.register(Sample,SampleAdmin)*


<https://lh3.googleusercontent.com/-0FFa5Z3E9tM/VU3ZFh0eonI/AAAAAAAAAYc/gHbjGVn4F-k/s1600/Screenshot%2Bfrom%2B2015-05-09%2B15%3A09%3A17.png>


When i try to insert a record from admin it shows the error, But when i 
tried only with parent table it works.When i came to add child table its 
not working.Its just shows "Please correct the error below".And then i 
tried to save through userinterface views(out of admin) it shows the 
following error "The inline foreign key did not match the parent instance 
primary key". 





-- 
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/854f71c8-2b21-4184-a533-497f39b236d6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to