ok, it looks very nice i will try and let you know.. thanks 2012/7/24 Tomas Neme <lacrymol...@gmail.com>
> > > as shown in the picture, this i could do by add a method in the model > > getTienda1 and return the stock and do it for each store, but i want it > to > > be created dinamically because the user could create a new store and it > will > > not be there. > > > > so this is my cuestion: can i do that? > > Interesting question. You COULD try the following: > > in the ProductAdmin ModelAdmin's class' __init__ you can define > list_display like > > from store.models import Tienda > for store in Tienda.objects.all(): > self.list_display.append('stock_tienda_{id}'.format(id=store.id)) > > this would give you the list of existing stores at server init time. > and then you could define your Product model's __getattr__ method > something like this: > > def __getattr__(self, attr): > base = 'stock_tienda_' > if attr[:len(base)] == base: > return > Product.objects.filter(tienda=Tienda.objects.get(id=attr[len(base):])) > return super(Product, self).__getattr__(self, attr) > > this should make the ModelAdmin's hack work > > finally, you need a way to add new columns for newly created stores, so > maybe a post_save signal on Tienda objects > > @receiver(post_save, sender=Tienda) > def add_to_product_list_display(sender, instance, new, **kwargs): > if new: > # I don't know how to get the ModelAdmin's instance for a given > class, > # but it must be something in django.contrib.admin.site > product_admin.list_display.append('stock_tienda_{id}'.format(id= > instance.id)) > > you probably need another listener before .delete of stores, and I'm not > certain the __getattr__ hack will work, but this sounds interesting. > > Please try on those lines, and let me know if this worked, I'm most > interested > > -- > "The whole of Japan is pure invention. There is no such country, there are > no such people" --Oscar Wilde > > |_|0|_| > |_|_|0| > |0|0|0| > > (\__/) > (='.'=)This is Bunny. Copy and paste bunny > (")_(") to help him gain world domination. > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-users@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > -- __ Ignacio Soto Reveco Staff IngeHost -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.