These are chat archives for django/django

Oct 2017
Renjith S Raj
Oct 16 2017 07:20
any django freelance projects availble?
kyadondo Timothy
Oct 16 2017 07:56
Hello, I have cached my template in the database but how do I reset it? For example when I have deleted something and I want to be reset how can I handle that?
Oct 16 2017 09:36
hy. i've got an issue with the way in should handle a user query...
def message(request):
    user = request.user
    message_form = messageForm()
    message_raw_form = messageRawForm()
    person = Person.objects.filter(user = user)
    data = []

    # function usefull to get a Person object. Else it stays a query object.
    def getPerson (person):
        for john in person:
            return john
    actual_person = getPerson(person)
Ok so i'm looping on a single element... There's got to be a way in Django of handling this in a better way. Any ideas?
Shobhit Sharma
Oct 16 2017 09:39
You could just do Person.objects.get(user = user)
Oct 16 2017 09:39
DISCLAIMER : that getPerson function was created to correct a error where Django was mad at me because queryset is not iterable, has no attibutes... Because person is really
<QuerySet [<Person: john>]>
Oct 16 2017 09:40
@sharmashobhit Thanks i'll try that. Sounds obvious, my bad.
@sharmashobhit Works perfectly ! Thanks.
Oct 16 2017 11:20
Luv Suneja
Oct 16 2017 12:47
Hi guys, How are you all doing? I need some help with FormView.

I've a database with table called Company... I need it to be searchable by Country, Type and Category... I've already configured the urls as CompanyBrowser/<Country>/<Type>/<Category> and it works fine by manually typing in the url bar. I made a django form as follows:

class SearchForm (forms.ModelForm):
    class Meta:
        model= Company
        fields = ['companytype','country']

and FormView as follows:

class SearchView(generic.edit.FormView):
Luv Suneja
Oct 16 2017 12:52
How do I make the formview read the posted data and redirect to the appropriate url
Also, Category is in another table called CompanyDetails which is linked to the Company table using foreignkey as one company can have several Categories
Oct 16 2017 13:37
@chiz use get_success_url
Luv Suneja
Oct 16 2017 13:38
So, I just read from the form class and construct a success_url, right
Luv Suneja
Oct 16 2017 13:59
Awesome, works well. I just modified the url in form_valid function by reading it from dictionary
Oct 16 2017 15:58
@emihir0 could that be used to redirect to the current page with a updated template? I'm having an issue where I only get the penultimate submission to show up after a form submission. As soon as I hit f5 I get my last submission as expected.
Oct 16 2017 18:23
Two questions here. I have two models, Company and People, and a web scraper that grabs all of that information. I want to run the web scraper when a user is looking at a company and the date is over a week old. Question 1 - how do I check the date in my view and then trigger the web scrapper? Question 2 - one web page contains all of this information, however I don't want to overwrite everything each time if I don't have to. What's the best way to each value, other than multiple if statements?