내 특성 모델이 내 데이터베이스에 두 번 저장되는 이유는 무엇입니까? 이상한 ... Django 모델이 두 번 생성 되었습니까?
여기 내보기 코드입니다 :@login_required(login_url='/login/')
@transaction.atomic()
@reversion.create_revision()
def add_item_type(request, id_item, id_item_type):
item = Item.objects.get(id=id_item)
item_type = ItemType.objects.get(id=id_item_type)
item.status = Item.DEPLOYED # Set to phase deployment
item.save()
for a in item_type.attribute_types.all(): # Create all attribute skeletons to item
Attribute.objects.create(name=a.name, description=a.description, type=a.attr_type, item=item)
ctx = {'item':item, 'item_type':item_type}
return render_to_response('des/item/add_item_type.html', ctx, context_instance=RequestContext(request))
편집 :
내 데이터베이스를 보면 (포스트 그레스) 내보기의 루프를 저장하지 (두 번 호출 발견 동일한 루프에서 두 번) 또는 내보기가 두 번 호출됩니다. 나는 이유를 모른다. 내 db에서 Attribute 클래스가 이와 같이 저장되기 때문에 이것이 루프 문제가 아님을 확신한다.
id - name
1 - fly
2 - sit
3 - run
4 - fly
5 - sit
6 - run
왜 그런가? 내 코드를 이해하려면 클래스로 ItemType을 참조하고 ItemType 클래스의 속성으로 AttributyType을 참조하고 Item은 ItemType을 인스턴스화하고 Attribute는 AttributeType을 참조하십시오.
음, 거기에 루프가 있습니다. 쉘에서'ItemType.objects.get (id = id_item_type)'의 결과를 확인하지 않으시겠습니까? –