python - Overwriting the save method of a Django model -


i have table of symbols. before add new symbol validate symbol.

for purpose have overwritten save method in model:

def save(self, *args, **kwargs):      if self.check_exist(self.name):         # call "real" save() method.         super(assetssymbol, self).save(*args, **kwargs)         else:         # yes, symbol not saved in database         # that's good. 

using 1 or 2 lines of code in else how can inform user has submitted invalid symbol?

django still reports symbol "test" has been saved (which misleading)

i try avoid using modelforms etc.

here's more current implementation:

@admin.register(assetssymbol) class assetsymboladmin(admin.modeladmin):     list_display = ("name", "group", "alive", "internal")     list_filter = ("name", "group", "alive", "internal")      ...     def save_model(self, request, obj, form, change):         if self.check_exist(obj.name):             messages.add_message(request, messages.success, 'valid bloomberg symbold {0}'.format(obj.name))             obj.save()         else:             messages.add_message(request, messages.error, 'invalid bloomberg symbol {0}'.format(obj.name)) 

the message invalid bloomberg symbol displayed correctly followed message symbol has been stored!?


Comments

  1. Bibliography Vs Works Cited might be required when utilizing Chicago or Turabian design references. It varies in that it expects you to list all sources utilized throughout your work, regardless of whether you have alluded to them explicitly in your paper or not.

    ReplyDelete
  2. We are a team of highly experienced and well trained, those who provide a solution related to McAfee.com/Activate,www.McAfee.com/Activate Product Key,www.McAfee.com/Activate ,windstream login and windstream email For more info contact our support team.

    ReplyDelete
  3. When I feel no point of arguing, then I go to Cheap Essay Writing Services and I discuss my problems with experts.

    ReplyDelete
  4. Looking for assignment help? Choose our assignment service at affordable price. To gather more information, or any question about assignment, please contact us

    ReplyDelete
  5. The blog is well organized with content as per readers interest, very clear description of terms and valuable source of data, looking forward for more of your useful updates, thanks for sharing. du post utme form

    ReplyDelete

Post a Comment

Popular posts from this blog

python - Specify path of savefig with pylab or matplotlib -

How to run C# code using mono without Xamarin in Android? -

c# - SharpSsh Command Execution -