Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
Repo info
    Juliano Ribeiro
    I had a error in my project, as I am a beginner with dev Django, I went to read the manual. But I remained a little confused. In my case I have the models called Clients and Hosts.
    Every Host belongs to a Client, so I added the id_client field as a foreign key, in the Host table, in the templates when I have to access the client name through the Host table do so for example: {{host.id_client.name}}.
    But when I was learning and trying to implement CRUD + AJAX on my project, when trying to create a new Hosts model record, I had to use id_client_id, for function "create ()" ...
    In the Models documentation, I found the paragraph "Database Representation" that says Django adds "_id", but would you like to understand if this is editable? Or should you rename the column FK?

    My models:
    class Clients(models.Model):
    id_client = models.BigIntegerField(primary_key=True, blank=True)

    class Hosts(models.Model):
    id_host = models.BigIntegerField(primary_key=True)
    id_client = models.ForeignKey('Clients', models.DO_NOTHING, db_column='id_client', related_name='host_client_id')

    obj = Hosts.objects.create(
    <others fields>
    hi ,I am new to django and I am getitn an error ..Exception Type: ValueError
    Exception Value:
    The view accounts.views.register didn't return an HttpResponse object. It returned None instead.
    while creating registeration form
    can someone help
    Mike Simkins
    @chauhan-ritik Is the last line of your method 'return HttpResponse........' ??
    i am getting ImportError: cannot import name 'RegistrationForm' from 'django.contrib.auth.forms'( /home/ritik/.local/lib/python3.7/site-packages/django/contrib/auth/forms.py)

    from django import forms
    from django.contrib.auth.models import User
    from django.contrib.auth.forms import UserCreationForm

    class Registrationform(UserCreationForm):
    email = forms.EmailField(required = True)

      class Meta:
            model =User
            fields =(
      def save(self,commit=True):
            if commit:
            return user
    can anyone help
    @msimkins thanks for the previous error
    Mike Simkins
    @chauhan-ritik I think your form is called Registrationform not RegistrationForm
    Ahmed Sallam Nassar Awad
    Hi, everyone, How can I make query string in django like
    Filip Lav Maksimovic
    @ahmed-sallam can you elaborate more on that?
    Ahmed Sallam Nassar Awad
    Thanks @maximlion , I mean , I want to make a query string in urls with key=value
    Filip Lav Maksimovic
    Hello everyone, is there a way I could add an attribute to all query objects using annotate? I basically just need to get a value from an m2m relationship of the object and save it as an attribute of the object.
    Something like this: query.annotate(value_to_be_added=("value_from_m2m"))
    @ahmed-sallam first you need to adapt your urls.py to accept a url parameter, then adapt the views get method to accept parameters and that should be it. This could help: https://stackoverflow.com/questions/150505/capturing-url-parameters-in-request-get
    Ahmed Sallam Nassar Awad
    @maximlion Thanks a lot, I will try it.
    Swaraj Pande
    Hey guys, new to django here :)
    Hey guys. SOS please. How do I write a URL pattern for a URL like this? weather/?current_location=-33.927407,18.415747&booking_location=-32.927407,19.415747
    When I do reverse(‘weather’, kwargs={‘current_location’: some_value, 'booking_ location’: another_value}) I am getting a NoReverseMatch exception.
    El 李天宝
    @swarajpande4 Welcome to the world :0
    @dubesoftware Too short. I need more detail on your question
    I need you see your urls.py and views.py
    El 李天宝
    national_card = models.ImageField(upload_to='./national_cards/', null=True, blank=True)
    How can I add encryption key to encrypt my national_card?
    And frontend will decrypt it by itself
    hardik Gajjar
    Implement your custom storage class for your encryption
    El 李天宝
    Thank you
    Brian Edelman

    I am using Django Rest Framework and have a model with a timestamp field that I want to group by. The outcome I would like is to have something like {tournament_count: 2, start_date: datetime object, tournaments: [{...tournaments model representations}]} I currently have a queryset returning the tournament_count and start_date but now I want to drop in the actual tournaments as well.

                    start_date=Trunc("time_stamp", "day", output_field=DateTimeField())

    I can't figure out a solution that will work well and scale well. Any thoughts?

    I am using django email message class ,and getting the above error ,any help is highly appreciated
    Just figured out the problem in case someone has read it. The system uses [ user_id, user_name ] as choices, not [ User instance, user_name ].
    James Komo

    Hello people, has anyone here managed to create user profiles while using Django allauth for authentication. I am having challenges with user has no profile errors and RelatedObjectDoesNotExist a yet I have a Profile model with OnetoOne relationship with User model and a profile view plus use of Django signals for profile creation and saving



    from django.shortcuts import render, redirect
    from django.contrib import messages
    from django.contrib.auth.decorators import login_required
    from .forms import ProfileUpdateForm

    def profile(request):
    if request.method == 'POST':
    p_form = ProfileUpdateForm(request.POST,
    if p_form.is_valid():
    messages.success(request, f'Your account has been updated!')
    return redirect('profile')

        p_form = ProfileUpdateForm(instance=request.user.profile)
    context = {
        'p_form': p_form
    return render(request, 'profile.html', context)


    class Profile(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE)
    image = models.ImageField(default='default.jpg', upload_to='profile_pics')
    role = models.CharField(max_length=25,choices=role, default='Freelancer')

    def __str__(self):
        return f'{self.user.username} Profile'


    @receiver(post_save, sender=settings.AUTH_USER_MODEL)
    def create_profile(sender, instance, created, **kwargs):
    if created:

    @receiver(post_save, sender=User)
    def save_profile(sender, instance, **kwargs):


    El 李天宝
    @jameskomo From my experience I recommend thick Form or Serializer, but not implement signal
    Help I have a question
    ORM question
    Falgun Swami
    Hi i need some help regarding django.
    So i have a database.py file which loads a json file. I want to be able to configure this database file as a database in my django app. I have tried to find ways to do it but failed. Any help will be appreciated. Thanks
    James Komo

    Does anyone know how to query another model based on Foreign Key? Say I have a Project model that is a FK in task model and I want to generate all the task_names by querying the Task model and only see tasks applicable to a specific project?

    Tried doing this and it is not working project_tasks=Task.objects.filter(project_id__in=Project.objects.all()).order_by('latest_submission_time')

    hey, i have question about django admin can someone help me