Hi
exist some settings to only insert X number of rows in a model?

django.db. (i guess, restrict 5 rows)   as simple way ?

or

setting directly into MySQL  ?

because, i override the save method to check if:

# models.py
class domain(model.Model):
    ...
    max_accounts = models.IntegerField(default=2)


# admin.py

class UserAdmin(admin.ModelAdmin):
    list_display = ('user', 'domain',  'max_account')
    ordering = ('user',)

    def save_model(self, request, obj, form, change):
        max_accounts = domains.objects.all()
        accounts = users.objects.all()
        if  int(max_accounts.values()[0]['max_accounts']) >
accounts.count():
            super(UserAdmin, self).save_model(request, obj, form, change)
        else:
            messages.error(request, "Impossible create more accounts.")

In this code .. the check works... but my problem is:

when account 1 and total is 2 is fine.. save in mysql
when account 2 and total is 2 is fine and save in mysq again
when account is 3 and total is 2 i got the error... not save (because the
logic is fine)

and
django admin output the error message BUT show the OK was successfull
inserted too
(as a fake insert) ...how can I omit the OK message.?

thanxs in advance

-- 
Antonio Peña
Secure email with PGP 0x8B021001 available at https://pgp.mit.edu
<https://pgp.mit.edu/pks/lookup?search=0x8B021001&op=index&fingerprint=on&exact=on>
Fingerprint: 74E6 2974 B090 366D CE71  7BB2 6476 FA09 8B02 1001

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALBaCdtCK9_JQ0Xv5k0dAxWiudXReoOg%3D5Gxbs52jpNwqd25aw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to