0
我不明白爲什麼當我嘗試查看我向患者添加的過敏症時出現錯誤?ManytoManyField Django關係錯誤
def create_allergie(request):
if request.method == 'POST':
try:
print 'In create_allergie()'
allergy = Allergie()
allergy.name = request.POST['name_allergie']
allergy.id_allergie = 1065
allergy.intensity = 10
allergy.add_by = int(request.POST['user_pk'])
allergy.deleted = False
allergy.deleted_date = '20-09-2014:20:10:05'
allergy.deleted_by = 5
allergy.save()
print '-- ALLERGIE SAVE --'
pk_patient = int(request.POST['patient_pk'])
my_patient = get_object_or_404(Patient, pk=pk_patient)
print my_patient
allergy.patient.add(my_patient)
print '---- DISPLAY TABLE ----'
print 'PATIENT : ', allergy.patient.all()
print 'ALLERGY : ', my_patient.allergie_set.all()
except Exception, b:
print b
raise b
return render_json([])
我把這裏的輸出我得到:
在create_allergie()
- ALLERGIE SAVE -
移動Joee
----顯示錶 - ---
患者:[患者:手機喬伊]
過敏: 'Allergie' 對象有沒有屬性 '內容'
我也給你的模型 'Allergie':
class Allergie(models.Model):
name = models.CharField(max_length=25, verbose_name="Nom de l'allergie")
id_allergie = models.IntegerField()
intensity = models.IntegerField()
add_date = models.DateTimeField(auto_now_add=True, auto_now=False, verbose_name="Date d'ajout de l'allergie")
add_by = models.IntegerField()
deleted = models.BooleanField()
deleted_date = models.CharField(max_length=255, verbose_name="Date de suppression de l'allergie")
deleted_by = models.IntegerField()
patient = models.ManyToManyField(Patient)
def __unicode__(self):
return unicode(self.content)
class Meta:
verbose_name = "Allergie"
verbose_name_plural = "Allergies"
我希望有人能幫助我...謝謝
Ohhh是@cezar,你讓我開心,多謝了很多傢伙! – Atom 2014-10-09 09:22:52