Filtering multiple model values in Django -
i using django 1.11.4 , python 2.7
so have models
class vehicle(models.model): auto_maker = ( (‘chevy’, ‘chevrolet’), (‘ford’, ‘ford’), (‘nissan’, ‘nissan’), (‘lamborghini’, ‘lamborghini’), (‘ferrari’, ‘ferrari’), (‘dodge’, ‘dodge’), (‘tesla’, ‘tesla’), (‘jeep’, ‘jeep’) ) auto_maker_brand = models.charfield(max_length=12, choices=auto_maker) model_name = models.charfield(max_length=100) release_year = models.datetimefield() added_to_db_date = models.datetimefield() image_url = models.urlfield(max_length=500) description = models.textfield() default_value = models.positivesmallintegerfield(default=0)
and want able have filter able have last n records of added_to_db_date
, of auto_maker_brand
objects filtered can use in template
<h1>car maker</h1> <h2>chevy:</h2> <!— last 10 added chevy list each 1 in div along image—> <h2>ford:</h2> <!— last 10 added ford list each 1 in div along image—>
and on rest of auto maker brands want include part added_to_db_date
returns last 10 added vehicles image , understand how last 10 added in views
def home(requests): value = vehicle.objects.filter(default_value=0).order_by(‘-id’)[:10] return render(requests, ‘home.html’, name=‘home’, {‘value’=value})
and template so
{% value in value %} <a href=“#” ><img src=“{{ value.image_url }}/>{{ value.model_name }}</a> {% endfor %}
but how last 10 added each auto brand filtered me use , able include of them along added on same template?
wiki
Comments
Post a Comment