27๐
your view function name is defined as Like
and your model is named Like
you define Like
as a function so when you go to access Like.objects
python does not see your model Like
but the function Like
you could rename your view function
url(r'^like/(?P\d+)/$', 'pet.views.change_name_no_conflict', name = 'Like' )
def change_name_no_conflict(request,picture_id):
pass
- Deciding and implementing a trending algorithm in Django
- Extending generic view classes for common get_context_data
- Update_or_create with ManyToManyField
- Why does Django use tuples for settings and not lists?
- Checking if a Django user has a password set
1๐
This is because your function name in view.py and model name in models.py are the same.
You can change the function name or model name.
Another solution is:
from .models import modelname as modelname2
def modelname(request):
obj_list_ads = modelname2.objects.all()
in this code function name is modelname.
- Check if a function has a decorator
- Logging formatters in django
- Hiding secret key in django project on github after uploading project
- Django subclassing multiwidget โ reconstructing date on post using custom multiwidget
0๐
I got this same error when doing
from django.contrib.auth import get_user_model
User = get_user_model
adding () solved the error:
from django.contrib.auth import get_user_model
User = get_user_model()
- Check if a function has a decorator
- Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:
0๐
function name and model name does depend on name, function name should be same as url name we define url in urls.py model name depend on function data member, its means as for example when we take data from user and save in database then we call that object from its model name ex= u_data = registration() ,this is used for user data seve and define that fun where we send data to save means target url and in its related view.
- Can I get expiration time of specified key in django cache?
- Django REST: How to use Router in application level urls.py?
- Serialize multiple models and send all in one json response django rest framework
- Multi-Tenant Django Application
- Get Celery to Use Django Test DB
0๐
I hit this error because my viewโs query set looked like this:
class IngredientList(generics.ListAPIView):
queryset = Ingredient.objects.all # This line is wrong
serializer_class = IngredientSerializer
I fixed it by adding a set of parenthesis to the queryset line:
class IngredientList(generics.ListAPIView):
queryset = Ingredient.objects.all() # Fixed
serializer_class = IngredientSerializer
- Is Django Book platform available?
- Retrieving the 'many' end of a Generic Foreign Key relationship in Django
- Django-rest-swagger nested serializers with readonly fields not rendered properly
- Django and service workers โ serve "sw.js" at application's root url
- Django CSRF when backend and frontend are separated
- Django Check and set permissions for a user group