Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Filip Lav Maksimovic
    @maximlion
    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
    @ahmed-sallam
    @maximlion Thanks a lot, I will try it.
    Swaraj Pande
    @swarajpande4
    Hey guys, new to django here :)
    SD
    @dubesoftware
    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.
    :]
    @elcolie
    @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
    :]
    @elcolie
    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
    @gajjar8055
    Implement your custom storage class for your encryption
    :]
    @elcolie
    Thank you
    Brian Edelman
    @brianedelman

    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.

    queryset.annotate(
                    start_date=Trunc("time_stamp", "day", output_field=DateTimeField())
                )
                .values("start_date")
                .annotate(tournament_count=Count("id")).order_by()

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

    Hi
    All
    I am using django email message class ,and getting the above error ,any help is highly appreciated
    Bo
    @BoPeng
    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
    @jameskomo

    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

    Users/views.py

    `views.py

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

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

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

    `

    MODELS.PY
    `
    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'

    `

    SIGNALS.PY
    `
    @receiver(post_save, sender=settings.AUTH_USER_MODEL)
    def create_profile(sender, instance, created, **kwargs):
    if created:
    Profile.objects.create(user=instance)
    profile.save()

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

    `

    :]
    @elcolie
    @jameskomo From my experience I recommend thick Form or Serializer, but not implement signal
    Help I have a question
    ORM question
    Falgun Swami
    @swamifalgun
    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
    @jameskomo

    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')

    Buğra
    @BgR8
    hey, i have question about django admin can someone help me
    how can i export a user to pdf
    matrixbot
    @matrixbot
    Buğra
    @BgR8
    @matrixbot it was not
    how can i export a user to pdf
    is there a solution
    matrixbot
    @matrixbot
    qamarali I think you want to export user data from model to PDF,
    So check it out this link
    https://www.hexascholars.com/code-snippet/export-model-data-into-pdf-in-django/
    Buğra
    @BgR8
    yes in admin panel @matrixbot
    Yorman Aguirre
    @yaguirre
    Hi
    I'm Django developer, new in the community
    Happy to be here :D
    Alejandro Duque Correa
    @aleducode
    Hi @yaguirre from medellin col :)
    dotbrt
    @dotbrt
    Hi everyone! I’m a django beginner (generally a beginner dev)
    I have a question. I’m working through yet another guided project. This time Django Girls. In other projects, everyone simply put the app name into settings.py file, in INSTALLED_APPS. Django Girls did ‘blog.apps.BlogConfig’. What does the .app.BlogConfig part change? I assume it must be created as it’s a custom name, but is there any difference if I just put an app name?
    So in this case ‘blog’ vs. 'blog.apps.BlogConfig'
    matrixbot
    @matrixbot
    qamarali This link will definitely help you out...
    https://docs.djangoproject.com/en/3.0/ref/applications/
    :]
    @elcolie
    @dotbrt What ever your PYTHON_PATH can read
    Reza_XD
    @rezaxd
    @dotbrt hi the "blog.app.BlogConfig" means from app.py in blog folder read the name if the app name.
    matrixbot
    @matrixbot
    thisisshub Can somebody help me with "how to set the STATIC_ROOT in settings.py". I am trying to deploy my app on heroku but I keep getting error Error while running '$ python manage.py collectstatic --noinput'. even though I do have a STATIC_ROOT path in my setttings.py