These are chat archives for django/django

29th
Sep 2017
MilanRgm
@MilanRgm
Sep 29 2017 02:19
class Resume(models.Model):
    applicant = models.OneToOneField(User, on_delete=models.CASCADE)
    name = models.CharField(max_length=100, blank=False, null=False, help_text="Full Name")

class Education(models.Model):
    resume = models.ForeignKey(Resume, related_name='education')
    name = models.CharField(max_length=100, blank=False, null=False, help_text="Name of an institution")

I want to list all the education that is under the resume of requested user

education_instance = Resume.objects.filter(applicant=request.user).prefetch_related('education')

print(education_instance) #this is giving me the resume instance not the list of education

matrixbot
@matrixbot
Sep 29 2017 04:45
@bignose:matrix.org MilanRgm (Gitter): Education.resume is a models.ForeignKey(Resume).
So that means Resume gains a field – by default named Resume.education_set – that is a QuerySet of all Education instances that reference that specific Resume instance.
@bignose:matrix.org MilanRgm (Gitter): so gven an instance of resume, you can useresume.education_set as a QuerySet to access all of its Education instances.
@bignose:matrix.org MilanRgm (Gitter): you have chosen to name the field education, which is confusing. I would recommend instead a name that indicates it is a collection or query set.
The default, education_set, is good enough IMO.
patient
@patient
Sep 29 2017 04:48
@MilanRgm You have to rename related_name to "educations" for more understandable. user.resume.educations.all()
And use debugging instead prints... It gives more abilities for exploring issues
Pavel Burns
@63phc
Sep 29 2017 04:56
How do I make that when selecting in the form of a field, another field was loaded, depending on the choice
?
patient
@patient
Sep 29 2017 04:57
On frontend?
Like AJAX loading?
Pavel Burns
@63phc
Sep 29 2017 04:57
yep
There is a user model, there is a field of co-operation, when a form is selected in the form, then other fields are loaded
patient
@patient
Sep 29 2017 04:58
Make API and write JS-code. But you have to control validation of these fields relations on backend-form-level
The task includes two parts: frontend JS and backend API with dynamic fields in serializer
Pavel Burns
@63phc
Sep 29 2017 05:01
but there is an example
?
patient
@patient
Sep 29 2017 05:03
Give more about your case. I think it is like: select country -> (load cities) select city -> (load streets). Right?
MilanRgm
@MilanRgm
Sep 29 2017 05:06
@patient I did not understand about the user.resume.educations.all() part
Yeah I renamed all my related_name to plural :)
matrixbot
@matrixbot
Sep 29 2017 05:20
@bignose:matrix.org MilanRgm (Gitter): the Resume.educations is a QuerySet instance. Look up Django query sets, how to use them.
MilanRgm
@MilanRgm
Sep 29 2017 05:38
Thanks @matrixbot
Pavel Burns
@63phc
Sep 29 2017 06:27
@patient yeep
:]
@elcolie
Sep 29 2017 07:53
Hi
Renjith S Raj
@renjithsraj
Sep 29 2017 07:53
hi
This is my problem right now.
The plain simple way is let user himself continously refresh the summary page. But I want that to be the last choice
Rod
@sixtycycles
Sep 29 2017 20:15
hey everyone! any idea why my flatpages override to use redactor as a WySIWYG editor is displaying three text fields, rather than one? this is what i have here:
from django.contrib import admin
from django.contrib.flatpages.forms import FlatpageForm
from django.contrib.flatpages.models import FlatPage
from django.contrib.flatpages.admin import FlatPageAdmin
from redactor.widgets import RedactorEditor
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django import forms
class FlatPageForm(forms.ModelForm):
    content = forms.CharField(widget= RedactorEditor())

    class Meta:
        model = FlatPage
        fields = '__all__'

class FlatPageCustomAdmin(FlatPageAdmin):
    form = FlatpageForm
    formfield_overrides = {
        models.TextField: {'widget': RedactorEditor()},
    }
    fieldsets = (
        (None, {'fields': ('url', 'title', 'content')}),
        (_('Advanced options'), {'classes': ('collapse',),
        'fields': ( 'sites', 'registration_required', 'template_name')}),
    )
    list_display = ('url', 'title')
    list_filter = ('sites', 'registration_required')
    search_fields = ('url', 'title')

    class Media:
        css = {
            'all': (
                '/static/redactor/css/redactor.css',
                '/static/redactor/css/django_admin.css',
                )
        }
        js = (
            '/static/redactor/jquery.redactor.init.js',
            '/static/redactor/redactor.min.js',
            '/static/redactor/toolbars/default.js',
            )
admin.site.unregister(FlatPage)
admin.site.register(FlatPage, FlatPageCustomAdmin)
what i want to do is apply the widget only to the field for 'content'
i am also running FLatpages w/o an app
Rod
@sixtycycles
Sep 29 2017 20:29
@sixtycycles ok i figured it out. for some reason the class Media: css = { 'all': ( '/static/redactor/css/redactor.css', '/static/redactor/css/django_admin.css', ) } js = ( '/static/redactor/jquery.redactor.init.js', '/static/redactor/redactor.min.js', '/static/redactor/toolbars/default.js', ) was causing this effect.
removing it restores default behaviour