Django外键引用对象还是uuid?在这里正确的方式

时间:2015-10-13 18:40:12

标签: django database model

尝试理解一些Django

我有类似的东西(遗漏了其他字段):

$('[name="iluria-product-variation2"]').prop('disabled', true); 

$(document).on('click' , 'input[name="iluria-product-variation1"]'  , function(){
    $('[name="iluria-product-variation2"]').prop('disabled', false) 
});

$('[name="iluria-product-variation2"]').click(function(){
    $('[name="iluria-product-variation2"]').siblings('label').removeClass('checked');
    $(this).siblings('label').addClass('checked');
    $choice = $(this).attr('value');
    $('select#iluria-product-variation1 option[value=' + $choice + ']').attr('selected',true).parent().trigger('change');
    $('select#iluria-product-variation2 option[value=' + $choice + ']').attr('selected',true).parent().trigger('change');
});

$('[name="iluria-product-variation1"]').click(function(){
    $('[name="iluria-product-variation1"]').siblings('label').removeClass('checked');
    $(this).siblings('label').addClass('checked');
    $choice = $(this).attr('value');
    $('select#iluria-product-variation1 option[value=' + $choice + ']').attr('selected',true).parent().trigger('change');
    $('select#iluria-product-variation2 option[value=' + $choice + ']').attr('selected',true).parent().trigger('change');
});

$('select#iluria-product-variation1').on('change' , function(){
    $('[name="iluria-product-variation2"]').prop('disabled', true);
});

在使用extendedReservation创建reserrvation而不是null / none时,是否期望Reservation对象或Reservation ID?

我应该这样做(引用对象或uuid?):

class Reservation(Model):
   extendedReservation = models.ForeignKey('Reservation', default=None, blank=True, null=True)

    reservation = Reservation.objects.create(user=forUser, resource=resource, timeFrom=timeFrom, timeTo=timeTo, extendedReservation=extendedReservation)

1 个答案:

答案 0 :(得分:1)

如果你的uuid字段是模型的主键,你应该能够使用这两种变体来传递外键的值。