This is my admin.py:
这是我的admin.py:
class TransactionInfoAdmin(admin.ModelAdmin):
search_fields=['transactionId','subscriptionInfo__customerNumber']
save_on_top = False
def has_add_permission(self,request):
return False
def has_delete_permission(self, request, obj=None):
return False
def get_readonly_fields(self, request, obj=None):
if obj:
return self.readonly_fields + ('subscriptionInfo','transactionId','authorizationId','responseCode','operation','batchNumber','merchantId')
return self.readonly_fields
def save_model(self, request, obj, form, change):
#SUCCESS ACTIONS
obj.subscriptionInfo.paid = 1
obj.save()
pass
When I am saving the obj.subscriptionInfo.paid = 1
its not updating the data row, any ideas why?
当我保存obj.subscriptionInfo.paid = 1时它没有更新数据行,任何想法为什么?
NOTE: subscriptionInfo is foreign key in the above model TransactionInfo.
注意:subscriptionInfo是上述模型TransactionInfo中的外键。
-------------------------- UPDATE --------------------------
--------------------------更新----------------------- ---
My model.py
class SubscriptionInfo(models.Model):
subscriptionId = models.CharField(max_length=50)
customerNumber = models.IntegerField()
subscriptionType = models.CharField(max_length=50, default="basic")
currency = models.CharField(max_length=50, default="NOK")
paid = models.IntegerField(default=0)
class Meta:
verbose_name = "Subscription Information"
verbose_name_plural = "Subscription Information"
def __unicode__(self):
return u'%s' % self.customerNumber
class TransactionInfo(models.Model):
subscriptionInfo = models.ForeignKey(SubscriptionInfo, db_column='f')
authorizationId = models.IntegerField()
transactionId = models.TextField()
batchNumber = models.IntegerField()
merchantId = models.IntegerField()
operation = models.CharField(max_length=50)
responseCode = models.CharField(max_length=50)
paidDate = models.DateField(_("Date"), default=datetime.date.today)
class Meta:
verbose_name = "Transaction Information"
verbose_name_plural = "Transaction Information"
def __unicode__(self):
return u'Transaction : %s' % self.pk
Anyone?
1 个解决方案
#1
6
you have to call:
你必须打电话:
obj.subscriptionInfo.save()
as it's on a separate model, it will look something like this:
因为它在一个单独的模型上,它看起来像这样:
def save_model(self, request, obj, form, change):
#SUCCESS ACTIONS
obj.subscriptionInfo.paid = 1
obj.subscriptionInfo.save()
obj.save()
#1
6
you have to call:
你必须打电话:
obj.subscriptionInfo.save()
as it's on a separate model, it will look something like this:
因为它在一个单独的模型上,它看起来像这样:
def save_model(self, request, obj, form, change):
#SUCCESS ACTIONS
obj.subscriptionInfo.paid = 1
obj.subscriptionInfo.save()
obj.save()