Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
Repo info
  • Jul 14 16:11
    @MadLittleMods banned @Rehmanjeff
James Komo


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
how can i export a user to pdf
@matrixbot it was not
how can i export a user to pdf
is there a solution
qamarali I think you want to export user data from model to PDF,
So check it out this link
yes in admin panel @matrixbot
Yorman Aguirre
I'm Django developer, new in the community
Happy to be here :D
Alejandro Duque Correa
Hi @yaguirre from medellin col :)
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'
qamarali This link will definitely help you out...
El 李天宝
@dotbrt What ever your PYTHON_PATH can read
@dotbrt hi the "blog.app.BlogConfig" means from app.py in blog folder read the name if the app name.
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

I have a dictionary which contains one item (“current_location”, which is a nested dict) and I would like to access that nested dict. However, I cannot use the key as the code will break if a different key is passed, e.g. “different_location".

How can I access the first item in a dictionary without using a key? The dict looks like this:

{'current_location': {'date': '2020-01-27T10:28:24.148Z', 'type_icon': 'partly-cloudy-day', 'description': 'Mostly Cloudy', 'temperature': 68.28, 'wind': {'speed': 10.48, 'bearing': 178, 'gust': 12.47}, 'rain_prob': 0.02, 'latitude': '-33.927407', 'longitude': '18.415747', 'request_id': 31364, 'request_location': 'Current location'}}

Got it. I used dict[next(iter(dict))]
James Komo
Anyone who is familiar with using set.all in django in One-to-many relationship tables?

I have these two models

class Project(models.Model):
    project_name = models.CharField(max_length=100, blank=False)
    description = models.TextField(max_length=500, default=None)
    postedOn = models.DateTimeField(auto_now_add=True, blank=True)
    Owner = models.ForeignKey(User, on_delete=models.CASCADE)
    isCompleted = models.BooleanField(default=False)
    deadline = models.DateTimeField(blank=True, null=True)
    task_count = models.IntegerField(default=0)
    attachments=models.FileField(default='Project Attachments', upload_to='tasks_docs', validators=[validate_file_extension])

    def __str__(self):
        return self.project_name

class Task(models.Model):
    task_name = models.CharField(max_length=50, blank=False)
    addedOn = models.DateTimeField(auto_now_add=True, blank=True)
    project = models.ForeignKey(Project, on_delete=models.CASCADE, default=1)
    rating = models.DecimalField(default=0, max_digits=2, decimal_places=1)
    amount = models.IntegerField(default=0)
    task_description = models.TextField(max_length=1000, default=None)
    task_link = models.URLField(blank=True)
    latest_submission_time = models.DateTimeField(blank=True, null=True)
    isCompleted = models.BooleanField(default=False)
    deadline = models.DateTimeField(blank=True, null=True)
    task_attachments=models.FileField(default='Tasks To Do', upload_to='tasks_docs', validators=[validate_file_extension])

    def __str__(self):
        return self.task_name

And I am looking for a way to access tasks based on project. I can select a specific project and view its tasks

Mihail B
@jameskomo try this:
project = Project.objects.get(id=123).prefetch_related('task_set')
you can also specify related_name for project property in Task
Dipto Karmakar
Hi ,
Is there anybody who can provide me some good resources for implement social authentication in Django-rest api?
Thanks :)
El 李天宝
Supposed you have new feature that need geoDjango which is rely on postgist
Will you add extension to existing database and work with it or split it out to be new microservice over REST API?

Hi, I have a quick question.

Say I have models called "Post" and "Reaction" and I have made a Post, saved it and now I want to react on it with a Reaction.
Now, when I visit my feed where a list of Posts is, I want to show my reaction if I had one.

Which means:
{% if post.my_reaction %}{{ post.my_reaction.contents }}{% endif %}
Now, obviously I want to load more than just one Post; posts which don't have my reactions on it.

I know that I used to solve this with SQL in PHP with
LEFT JOIN Reaction ON Reaction.Post = Post.id
How do I do this in Django ORM ??
Hello everyone, i newbie and have some basic sites on django, pls suggest good book about django :)
m8, there's so much material online...
Did you try following the tutorial that Django provides on their Website?
I think i past that, have more that 2 basic sites, seek for book like 'Fluent Python'. btw don't really bother with it, just asking
Python or Django??
about Django, same level as 'Fluent Python' to python. More like reference book, with in-deep stuff
Hmmm I don't know anything like that.
Nwm :)
you should try the book "building django 2.0 web applications"
it's very detailed and touches on alot of concepts