L
L
Lone_Wanderer2020-01-19 18:00:59
Django
Lone_Wanderer, 2020-01-19 18:00:59

How to change the look of filters in a template in django-filer?

Hello everyone. Who fumbles for django-filter, please explain how to change the template.
This is my model

class Citys(models.Model):
    City = models.CharField('Населёный пункт', max_length=200, db_index=True)
    def __str__(self):
        return self.City
class Flats(models.Model):
    Citys = models.ForeignKey(Citys, on_delete = models.CASCADE)
    Flat = models.CharField('Ктанегория', max_length=200, db_index=True)
    Method = models.CharField('Способ приобретения', max_length=200, db_index=True)
    Price = models.DecimalField('Цена', max_digits = 9,  decimal_places= 2)
    def __str__(self):
            return self.Flat

This is my template code
<form action="" method="get">
  {{ filter.form.as_p }}
  <input type="submit" />
</form>

This is my filter code
class FlatsFilter(django_filters.FilterSet):
    class Meta:
        model = Flats
        fields = {
                  'Flat': ['exact'], 
                  'Method': ['exact'],
                  'Citys': ['exact'],
                  'Price': ['range'],
                  }

1 How to make lines where to enter the data, make the width and make some inscription in them
2 How to mark the inscriptions or delete them (the inscriptions are: "Ktanegory", "Acquisition method:", "Cities" ...)
JimQ8.png
3 How to make such price range
W10Pr.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Deleting Account, 2020-01-19
@Lone_Wanderer

0) Pzh, ask questions competently, without errors, and clearly. And ask only 1 question per post.
1) Change model to TextField or just change the widget.
. And what's stopping you from changing them with CSS, JS, JQ. If you really want to, you can generally copy the result {{ filter.form.as_p }}from the element code, and replace it with your own based on the copied one (however, it's better not to do this unnecessarily).
2) If you are talking about something, then try to set their value like this:<label><input/>

class FlatsFilter(django_filters.FilterSet):
    class Meta:
        model = Flats
        fields = {
                  'Flat': ['exact'], 
                  'Method': ['exact'],
                  'Citys': ['exact'],
                  'Price': ['range'],
                  }
        label = {
            'Flat' : 'Надпись'
           #......
        }

If it doesn't help then just delete it or change it via CSS or JS(JQ). 3) CSS and JS can do wonders! Why don't you use them for this purpose. If you have questions while doing this step, then ask a separate question, only with the CSS and JS tag. (in general, if you want to be a Full Stack developer, then learn Front end) If you want to be a back end developer, then why do you need these goals? It's not your job! And read the documentation on FilterSet<label></label>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question