Posts

Showing posts with the label django-models

Django 2.0 Access Models (CREATE/REMOVE/FILTER) Standalone [without manage.py shell]

Django 2.0 Access Models (CREATE/REMOVE/FILTER) Standalone [without manage.py shell] I have a Django project and I wanted to generate some objects (from the models) What I'm trying to get at : Standalone Python Script to create bunch of objects and/or filter,delete. after importing the model with from apps.base.models import MyModel and setting up the configuration as the previous StackOverflow Questions suggested I was not able to run the script. from apps.base.models import MyModel import os os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myProject.settings") import django django.setup() from apps.base.models import MyModel Please note that this is on Django version 2.0.6 [Django 2.0+] . Correct settings have been used, ( i.e. myProject.settings ) myProject.settings After properly configuring everything else I get the following error: RuntimeError: Model class apps.base.models.MyModel doesn't declare an explicit app_label and isn't in an applicat...

Calling user follow/follower list in Django

Calling user follow/follower list in Django Hi Djangonauts, I am trying to get the user follows list(example like Instagram 'A' follows 'B') in the templates. I have tried almost everything I am not able to call it in the templates. What am I doing wrong My models (It's a monkey patch to the Django User model) class Profile(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) #other profile fields class Contact(models.Model): user_from = models.ForeignKey(User, related_name='supporter') user_to = models.ForeignKey(User, related_name='leader') def __str__(self): return '{} follows {}'.format(self.user_from, self.user_to) User.add_to_class( 'following', models.ManyToManyField( 'self', through=Contact, related_name='followers', symmetrical=False)) My views (not sure if this is correct) def get_context_data(self, *...