Created
November 12, 2012 12:49
-
-
Save hemache/4059231 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from django.shortcuts import render_to_response | |
| # - - - | |
| # views.py | |
| # - - - | |
| def search(request): | |
| if 'q' in request.GET: | |
| query = request.GET['q'] | |
| results = Adv.objects.filter(title__icontains=query, city__slug__icontains=query) | |
| else: | |
| query = "" | |
| results = None | |
| context = { | |
| 'query': query, | |
| 'results': results | |
| } | |
| return render_to_response('search/search1.html', context) | |
| # - - - | |
| # models.py | |
| # - - - | |
| class ChoiceCity(models.Model): | |
| slug = models.SlugField(unique=True) | |
| city = models.CharField(max_length=60) | |
| class Adv(models.Model): | |
| title = models.CharField(max_length=60) | |
| pub_date = models.DateTimeField(auto_now_add=True) | |
| namecar = models.CharField(max_length=60) | |
| city = models.ForeignKey(ChoiceCity) | |
| companymade = models.ForeignKey(ChoiceCompany) | |
| made_date = models.CharField(choices=years,max_length=10) | |
| gear = models.ForeignKey(ChoiceGear) | |
| detail = models.CharField(max_length=390) # lenghth shouldn't be more then 255 for wild database compability | |
| image1 = models.ImageField(upload_to='multiuploader_images/') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment