Category : django-tables2

I get this error when I want to filter by an item. "Select a valid choice. 37537 is not one of the available choices." I think the problem is with the ComparisonFilter class but i can’t figure out what the problem is. models class Drug(models.Model): name = models.CharField(max_length=255, null=True, blank=True) classification_code = models.CharField(max_length=255, null=True, blank=True) ..

Read more

I have in models.py class Product(models.Model): class Meta: abstract = True name = models.CharField(max_length=250) cost = models.IntegerField() class CPU(Product): SOCKETS = ( ( ‘AMD’, ( (‘AM3’, ‘Socket AM3’), (‘AM3+’, ‘Socket AM3’), (‘AM4’, ‘Socket AM4’), (‘TR4’, ‘Socket TR4’), )), (‘Intel’, ( (‘1336’, ‘Socket 1336’), (‘1156’, ‘Socket 1156’), (‘1155’, ‘Socket 1155’), (‘2011’, ‘Socket 2011’), (‘1356’, ‘Socket 1356’), ..

Read more

I am wanting to make tables to show total scores for both user and teams. Models: class Team(Model): team_name = models.CharField(max_length=20, null=True, blank=True) class Player(Model): player_id = models.IntegerField(unique=True, null=False, blank=False) player_first_name = models.CharField(max_length=20, null=True, blank=True) player_last_name = models.CharField(max_length=20, null=True, blank=True) class Game(Model): score = models.FloatField(null=False, blank=False) game_type = models.CharField(max_length=8, choices=GAME_CHOICES) team = models.ForeignKey(Team, on_delete=models.CASCADE) player ..

Read more

enter image description hereI am trying to run the django_tables2 tutorial but it shows error. Traceback (most recent call last): File "manage.py", line 23, in execute_from_command_line(sys.argv) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/init.py", line 365, in execute_from_command_line utility.execute() File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/init.py", line 339, in execute django.setup() File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/init.py", line 28, in setup apps.populate(settings.INSTALLED_APPS) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/apps/registry.py", line 86, in populate app_config = ..

Read more

How can I modify the render of my form ? I followed the tutorial from django-tables2 considering table filtering. My actual code : filters.py import django_filters from .models import Mrae class MraeFilter(django_filters.FilterSet): titre = django_filters.CharFilter(lookup_expr=’icontains’, field_name=’titre’, label=’Titre’) annee = django_filters.NumberFilter(lookup_expr=’year’, field_name=’date’, label=’AnnĂ©e’) class Meta: model = Mrae fields = [‘titre’, ‘pv_mentionne’, ‘date’, ‘date’, ‘commune’, ‘departement’] ..

Read more

I’m Trying to filter through a model but everytime I tried this error keeps happening: Exception Type: FieldError at /store/dashboard/utiles_dashboard/sliders/ Exception Value: Cannot resolve keyword ‘name’ into field. Choices are: id, image, order, slider, slider_id here is part of the code: views.py: class SliderListView(SingleTableMixin, generic.TemplateView): """ Dashboard view of the slider list. """ template_name = ..

Read more

Imagine you have the following table: views.py: class ActionView(SingleTableView, FormView, SingleTableMixin, FilterView): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context[‘filter’] = SnippetFilter(self.request.GET, queryset = self.get_queryset()) queryset = kwargs.pop(‘object_list’, None) if queryset is None: self.object_list = self.model.objects.all() context[‘actions’] = Action.objects.all() return context filters.py: class SnippetFilter(django_filters.FilterSet): class Meta: model = Action fields = (‘name’, ‘description’, ‘control’ ) action.html: ..

Read more

I would like to know if there is a way to filter on field in a Django table that is created with a dictionary instead of with a Model. I have a Model that has 2 properties: #models.py class DeviceConfiguration(Model): device = models.OneToOneField(Device, on_delete=models.CASCADE) config = models.JSONField() In that JSON lives some structured data that ..

Read more

settings.py MEDIA_ROOT = os.path.join(BASE_DIR, ‘media’) MEDIA_URL = ‘/media/’ models.py class Product(models.Model): name = models.CharField(max_length=250) image = models.ImageField() tables.py import django_tables2 as tables from .models import Product class ProductTable(tables.Table): class Meta: model = Product fields = ("image" ,"name") views.py In the views.py , I filter the model objects and get QuerySet import django_tables2 as tables from ..

Read more

I am trying to use https://github.com/jieter/django-tables2 to replace the default Django admin table that you see when you login into the admin part. All the examples that I have found are based on creating a different view for the Model where you want to use, for example https://github.com/jieter/django-tables2/blob/master/example/templates/base.html but in this case, I want to ..

Read more