> 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 Tiendafor 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.