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

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -