reverse(‘weather’, kwargs={‘current_location’: some_value, 'booking_ location’: another_value})
I am getting a NoReverseMatch exception.
urls.py
and views.py
media
url?
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?
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()
`
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')
qamarali
This link would help you outqamarali
I think you want to export user data from model to PDF,