by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • May 16 2015 16:59
    olasitarska commented #362
  • May 16 2015 16:59

    olasitarska on master

    Making post_detail.html more co… Merge pull request #362 from ve… (compare)

  • May 16 2015 16:59
    olasitarska closed #362
  • May 16 2015 16:57
    kvbik commented #362
  • May 16 2015 16:51
    veuu opened #362
  • May 16 2015 15:20
    hjwp commented #361
  • May 16 2015 15:16
    hjwp synchronize #361
  • May 16 2015 15:15
    hjwp synchronize #361
  • May 16 2015 15:12
    bmispelon commented #361
  • May 16 2015 15:08
    hjwp opened #361
  • May 16 2015 14:58
    bmispelon opened #360
  • May 16 2015 13:15
    bmispelon commented #359
  • May 16 2015 13:15

    bmispelon on master

    Provide alternative runserver c… Merge pull request #359 from Al… (compare)

  • May 16 2015 13:15
    bmispelon closed #359
  • May 16 2015 13:14
    keimlink commented #359
  • May 16 2015 13:13
    olasitarska commented #359
  • May 16 2015 13:09
    bmispelon commented #359
  • May 16 2015 11:53
    Almad opened #359
  • May 15 2015 20:00
    bmispelon commented #358
  • May 15 2015 19:59

    bmispelon on master

    fixing broken github link Merge pull request #358 from gs… (compare)

matrixbot
@matrixbot
ice_bear69 Never mind. I just deleted the db.sqlite3 file. Lol.
matrixbot
@matrixbot
ice_bear69 Do you guys use null=True?
Jim Margolis
@JimMargolis
Screen Shot 2020-07-31 at 4.20.44 PM.png
I am working on the Django Forms section of the tutorial, and for some reason my pencil icon is not displaying and the the plus button is on the left rather than the right. Also, the published date does not show.

I suspect this has something to do with CSS. Here's my blog.css file:
body {
padding-left: 15px;
}
.page-header {
background-color: #C25100;
margin-top: 0;
padding: 20px 20px 20px 40px;
}

.page-header h1, .page-header h1 a, .page-header h1 a:visited, .page-header h1 a:active {
color: #ffffff;
font-size: 36pt;
text-decoration: none;
}

.content {
margin-left: 40px;
}

h1, h2, h3, h4 {
font-family: 'Lobster', cursive;
}

.date {
color: #000000;
}

.save {
float: right;
}

.post-form textarea, .post-form input {
width: 100%;
}

.top-menu, .top-menu:hover, .top-menu:visited, {
color: #ffffff;
float: right;
font-size: 26pt;
margin-right: 20px;
}

.post {
margin-bottom: 70px;
}

.post h2 a, .post h2 a:visited {
color: #000000;
}

any ideas on why this might be happening? Would appreciate any help! Thanks

this is my base.html file

{% load static %}

<html>
<head>
<title>Sinks Canyon Avalanche Center</title>
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
<link href="//fonts.googleapis.com/css?family=Lobster&subset=latin,latin-ext" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="{% static 'css/blog.css' %}">
</head>
<body>
<div class="page-header">
{% if user.is_authenticated %}
<a href="{% url 'post_new' %}" class="top-menu"><span class="glyphicon glyphicon-plus"></span></a>
{% endif %}
<h1><a href="/">Sinks Canyon Avalanche Center</a></h1>
</div>
<div class="content-container">
<div class="row">
<div class="col-md-8">
{% block content %}
{% endblock %}
</div>
</div>
</div>
</body>
</html>

and my post_detail.html file:
{% extends 'blog/base.html' %}

{% block content %}
<div class="post">
{% if post.publlished_date %}
<div class="date">
{{ post.published_date }}
</div>
{% endif %}
{% if user.is_authenticated %}
<a href="{% url 'post_edit' pk=post.pk %}" class="btn btn-default"><span class="glyphicon glyphicon pencil"></span></a>
{% endif %}
<h2>{{ post.title }}</h2>
<p>{{ post.text|linebreaksbr }}</p>
</div>
{% endblock %}

ice_bear69 Is this tutorial good?
ice_bear69 Its description says, "Django 3.0 crash course tutorials. Building a customer management app from start to finish covering all the basics of the django framework."
ice_bear69 But some of the first videos were released before December 2, 2019
chunboxing
@chunboxing
hello, my best Django guys, here is a content from the Django Girls workshop tutorial:
Finally, hop on over to the "Web" page and hit Reload on your web app. (To reach other PythonAnywhere pages from the console, use the menu button in the upper right corner.) Your update should be live on https://subdomain.pythonanywhere.com -- check it out in the browser! If the blog posts on your PythonAnywhere site don't match the posts appearing on the blog hosted on your local server, that's OK. The databases on your local computer and Python Anywhere don't sync with the rest of your files.
my question is my blog posts on my PythonAnywhere site don't match the posts appearing on the blog hosted on my local server, how to do the next???
also the same request, when the databases on my local computer and python anywhere don't sync with the rest of my files, how I should do???
many thanks your attention.
chunboxing
@chunboxing
anybody online? thanks for your attention the followings:
PythonAnywhere command-line
$ workon <your-pythonanywhere-domain>.pythonanywhere.com
(ola.pythonanywhere.com)$ python manage.py collectstatic
[...]
the collect static does not work, how to do???
matrixbot
@matrixbot
ice_bear69 Anyone here have a recommended resource for learning Django?
ice_bear69 I think I get the basics
Lowe Wilsson
@datalowe
@jim276 Make sure you're in the correct directory (where you used git init or git clone). Make sure you've run the command git remote add origin <your_url_here>. If you go to your github repository on github you should see instructions about this, and what url to use
matrixbot
@matrixbot
ice_bear69 Heeelp
Abhishek suresh
@abhishekkoothur_twitter
Thank you so much @das-g . That actually helped me and its fixed now. Thank you so much. I am really impressed with how much help this Community is.
+----+

I have a new doubt. Any hints are appreciated. So I have a bunch of buttons(called as topics) and a drop-down. I want to basically map them to blog posts. For example:- if I click on a button that says "Horror" and then click on the week dropdown and select "Week 1", it should show only blog posts that have Horror and Week 1 mapped to it(this I already did and can be selected in the admin).

Any idea on how to approach this? I tried to Google before asking here obviously but can't find a specific answer to it.

Lowe Wilsson
@datalowe
@chunboxing The local and pythonanywhere/"production" database aren't supposed to have the same content/posts, just like the tutorial says. You can create new posts on pythonanywhere if you want to have some posts to work with there.
Lowe Wilsson
@datalowe
@chunboxing For collectstatic, it would help if you described what error you get, and if you can run collectstatic locally or not
Lowe Wilsson
@datalowe
@ice_bear69, the tutorial you linked is probably fine, things haven't changed drastically since dec 2019. It would be more of a problem if you used something from before dec 2017, when django 2.0 was released if I'm not mistaken. I like this book, but it's not free https://djangoforbeginners.com/
@icebear, you removed your post so it's hard to tell what issue you had... remember to import forms in your views.py file
Lowe Wilsson
@datalowe

@abhishekkoothur_twitter So if I understand you correctly, you essentially want to create a search view. First you have to create a url path that's something like posts/<str:catname>/<int:weeknum>/'. Then you need a view which has a customget_queryset` method, using techniques similar to what's described in the search tutorial you went through earlier. E. g.

def get_queryset(self):
    return Post.objects.filter(category=self.catname).filter(week=self.week)

Then you want a form that uses the correct widgets for collecting inputs, as you want them. You can read about widgets here. I would guess you want RadioSelect and Select. Once you've done that, you write a 'search input' view, which uses the form and forwards the user to the custom queryset view (using the HTML <form>'s action attribute).

Something like that anyway :)

SnakeWhisperer
@SnakeWhisperer

Hello. I'm having some trouble when submitting a form that has several fields.

I have a 'Notes' model, which has a text field and other different fields, but the one I want to edit for now is the text field only. I created a ModelForm from the Notes model and I'm looping over all the table rows that have a note that is related to a specific project. What I want is to display all the notes at once and be able to edit whichever I want (one or more at once) and then submit them. However, when I hit the submit button after editing any of them, nothing happens, they are not changed; except when I edit the last one, which updates the database table, but puts that value in all of those rows.

Here is my form
image.png
Here is my view
image.png
here is my template
image.png
I don't think it's necessary to use save(commit=False) because I'm not doing anything with the data before saving it, but saving directly didn't change anything. I also tried to change where the submit button is, but nothing happened either. Why is this only submitting the last text field and putting that text value in all of the rows in my table?
Lowe Wilsson
@datalowe
@SnakeWhisperer To understand what is going on, try running your server and going to the page with the forms. Use your browser's dev toolkit's "Inspect element" functionality. Use this to look at the HTML that django has generated for your forms. I'm guessing you'll find that all your forms have the same name attribute (note_text, I would guess). When the user POST's their data, only the last form's note_text value is sent with the POST request, I think. It effectively "overwrites" all the other forms' note_text value. From your view's perspective, the view receives a POST dictionary that has a note_text key, paired with whatever value that was input for the last form on the page. So when you feed that dictionary of key-value pairs into the NoteForm class call, each time the same value is used.
To achieve what you actually want to do, I would guess that you should use formsets. I haven't used them myself so I don't know if the docs are beginner-friendly on this subject, or if you're better off googling for a tutorial to understand how you can use them. Hope it helps anyway :)
If you want then please write something short later on if you do use formsets and make things work, it would help me learn too
SnakeWhisperer
@SnakeWhisperer

When the user POST's their data, only the last form's note_text value is sent with the POST request, I think. It effectively "overwrites" all the other forms' note_text value. From your view's perspective, the view receives a POST dictionary that has a note_text key, paired with whatever value that was input for the last form on the page. So when you feed that dictionary of key-value pairs into the NoteForm class call, each time the same value is used.

@datalowe That's exactly what's happening, and I don't really know how to access a specific element's data from my view. When modifying an existing model instance, I thought I could access it's pk, but I haven't been able to find how to do that—or if it would actually work. Although, when adding a functionality to add a new note, there would be no pk before it's saved to the database.

I'll check the formsets and see what I can do. Thank you very much. Great as always.

SnakeWhisperer
@SnakeWhisperer

@datalowe I was able to make my forms work with formsets, specifically with model formsets. This is because I am editing model instances. My current task is very simple, but I—and anyone else reading this—can build from here to more complex things.

I'm not updating anything on my forms.py file because, with this approach I ended up not using it.

Here is my view

image.png
SnakeWhisperer
@SnakeWhisperer
I've added extended comments to show what's happening. It's possible that I misunderstood something; I'm doing this for the first time. Also, note that, to create the formset, I'm using a queryset that filters the objects by their project_id; this is why I'm not using the forms.py file and doing everything here in the view.
This is my HTML
image.png