Wednesday, June 21, 2017

Re: import different entries using filter

Your clue is in the word "variable" that you used.  The "variables" for a Django model are its fields; so what you are looking for is a value stored in your model's field.

e.g.

service = food.objects.get(restaurant-name__icontains='burger-place').values_list('type_of_service', flat=True)

This assumes that your Django "Food" model has a  field called 'type_of_service'.

Another way to do this would be to first get the restaurant object:

place = food.objects.get(restaurant-name__icontains='burger-place')

Then you can more get to the fields that you need quite easily:

print(place.type_of_service)
print(place.product)

But you may need to think about your database design to ensure the right data is being stored in the right models/fields e.g.

https://stackoverflow.com/questions/32366294/database-design-for-food-ordering-system-mysql
http://www.wellho.net/resources/ex.php4?item=s154/sql


On Tuesday, 20 June 2017 06:11:23 UTC+2, jon stan wrote:
hey im trying to import one set of info from a database based on the name of something else if that makes sense.

basically in the database its setup like this:

   food-----------------------------------------------------------------
      restaurant-name       products         type of service
         
         (burger-place)        (burgers)           (fast food)
   -----------------------------------------------------------------------

im trying to display the products and service type based on the name but i cant figure out how todo that. here's what i have:

     views.py
          name = food.objects.get(restaurant-name__icontains='burger-place')
          prod = food.objects.filter(restaurant-name__icontains='burger-place').filter(products__icontains='burgers')
          service = food.objects.filter(restaurant-name__icontains='burger-place').filter(service__icontains='fast food')

but i cant get it to work correctly. i get 'burger-place' for the name, prod, and service variables for some reason. would i have to create completely separate models or is there a way i can get these variables based on the restaurant name?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/864df46a-1644-4891-a371-926d9fde8a3f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment