Basic note/trello app - how to link model object IDs

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Basic note/trello app - how to link model object IDs

Lylio
Hi everyone,

I'm new to Django and currently working on a very simple app. It's basically a note app, a bit like a Trello board but aimed at creating user-story cards for software development teams (code at https://github.com/Lylio/scrumbuddy_project).

I made a mock-up in Photoshop of how it's supposed to look:

 



I've got some basic functionality up and running - users can register and create a user-story card. When a new card is created, a title, description, time estimation are inputted. Cards are just displayed as list items in columns. I'm trying to add a button to the cards so that when it's clicked, the details of the card open up in a new and a user can edit the card info or delete it. 

A couple of noob questions:

1. To click on a card so it opens up and displays the details, am I right to say I should create a card.html file in the templates folder for this? 

2. I'm confused about how Django keeps track of the cards in my app - I presume each card object has an ID in the database and I'd need this ID in order to retrieve the card's details when it's clicked - but I'm unsure of how to link the two. In the two pictures above, say someone clicked on the 'class progression' card on the left... I'd like a new page to open up that display the details for that card and allows the user to edit the info or completely delete the card.

I'm maybe asking a bit much here - but I'm unsure of how complex these requirements are. It feels like it should be fairly straightforward. Any thoughts or advice would be greatly appreciated.

Thanks for your time

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/0c63ef85-83be-4822-9aa8-0937b4213276%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Basic note/trello app - how to link model object IDs

Gonzalo Delgado-2
Hi Lylio,

On 12/2/18 16:20, Lylio wrote:
> 1. To click on a card so it opens up and displays the details, am I right
> to say I should create a card.html file in the templates folder for this?

It isn't necessary, but it is a good idea
What you need is to create a view that renders such template.
I suggest you write your own view function that does that, but what
you'd usually do is just use a generic view and either pass it the
template you want to use, or name the template in a way the generic view
will find it on its own.
See:
https://docs.djangoproject.com/en/2.0/topics/class-based-views/generic-display/

> 2. I'm confused about how Django keeps track of the cards in my app - I
> presume each card object has an ID in the database and I'd need this
ID in
> order to retrieve the card's details when it's clicked - but I'm
unsure of
> how to link the two. In the two pictures above, say someone clicked on
the
> 'class progression' card on the left... I'd like a new page to open up
that
> display the details for that card and allows the user to edit the info or
> completely delete the card.

Yes, in general, every Django model instance has an id (unless you
specifically tell it not to), and you can use it to create urls for the
detail view I mentioned earlier. This is a good start, but you'll later
want to add a SlugField to your Card model, and use that instead of the
id so urls look nicer.

> I'm maybe asking a bit much here - but I'm unsure of how complex these
> requirements are. It feels like it should be *fairly *straightforward.
Any
> thoughts or advice would be greatly appreciated.

I can assure you using Django for a project like yours is *very*
straightforward.
When in doubt, revisit the Django tutorial. This part is a good one for
where you're at: https://docs.djangoproject.com/en/2.0/intro/tutorial03/


--
Gonzalo Delgado

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c13ffca9-7a4a-e153-86d8-198a4a2d197a%40gonzalodelgado.com.ar.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Basic note/trello app - how to link model object IDs

Lylio
Thanks for the reply Gonzalo, I really appreciate the feedback.

So, conceptually I understand how the remaining pieces of this app fit together - but could I ask for just a little more of your help as I'm struggling with coding the details of what's needed.

Let's start basic - I've got some 'cards' in my database and on one of the web pages the title of the card is presented in a list (with some CSS styling to present the list item as a rectangle):

<ul>
{% for card in cards.all %}
<li class="card">{{ card.title }} </li>
{% endfor %}
</ul>

I'd like to click on one of the items in the list and open up a new page showing all the database details for that particular list item (title, description, time of creation, etc). Roughly, would I change the list items into links:

<ul>
{% for card in cards.all %}
<li class="card"><a href='card.html/get(this_object_id)>{{ card.title }}</a></li>
       {% endfor %}
</ul>

Then there would be a new view defined, something like

def card(request):
object = get(this_object_id)
context = {'cards': object}
return render(request, 'scrumbuddy/card.html', context)

I know this code is incorrect, but is it roughly how I should proceed? Connecting the list item URL to the card view which I don't really understand how to do.

Many thanks

Lylio


On Tuesday, 13 February 2018 14:18:25 UTC, Gonzalo Delgado wrote:
Hi Lylio,

On 12/2/18 16:20, Lylio wrote:
> 1. To click on a card so it opens up and displays the details, am I right
> to say I should create a card.html file in the templates folder for this?

It isn't necessary, but it is a good idea
What you need is to create a view that renders such template.
I suggest you write your own view function that does that, but what
you'd usually do is just use a generic view and either pass it the
template you want to use, or name the template in a way the generic view
will find it on its own.
See:
<a href="https://docs.djangoproject.com/en/2.0/topics/class-based-views/generic-display/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fdocs.djangoproject.com%2Fen%2F2.0%2Ftopics%2Fclass-based-views%2Fgeneric-display%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEIbYQh65j0_XcOOsBb121PvmwKQQ&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fdocs.djangoproject.com%2Fen%2F2.0%2Ftopics%2Fclass-based-views%2Fgeneric-display%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEIbYQh65j0_XcOOsBb121PvmwKQQ&#39;;return true;">https://docs.djangoproject.com/en/2.0/topics/class-based-views/generic-display/

> 2. I'm confused about how Django keeps track of the cards in my app - I
> presume each card object has an ID in the database and I'd need this
ID in
> order to retrieve the card's details when it's clicked - but I'm
unsure of
> how to link the two. In the two pictures above, say someone clicked on
the
> 'class progression' card on the left... I'd like a new page to open up
that
> display the details for that card and allows the user to edit the info or
> completely delete the card.

Yes, in general, every Django model instance has an id (unless you
specifically tell it not to), and you can use it to create urls for the
detail view I mentioned earlier. This is a good start, but you'll later
want to add a SlugField to your Card model, and use that instead of the
id so urls look nicer.

> I'm maybe asking a bit much here - but I'm unsure of how complex these
> requirements are. It feels like it should be *fairly *straightforward.
Any
> thoughts or advice would be greatly appreciated.

I can assure you using Django for a project like yours is *very*
straightforward.
When in doubt, revisit the Django tutorial. This part is a good one for
where you're at: <a href="https://docs.djangoproject.com/en/2.0/intro/tutorial03/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fdocs.djangoproject.com%2Fen%2F2.0%2Fintro%2Ftutorial03%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEJYEpqWWr8l23vhZ42lh0Zl8T5fw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fdocs.djangoproject.com%2Fen%2F2.0%2Fintro%2Ftutorial03%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEJYEpqWWr8l23vhZ42lh0Zl8T5fw&#39;;return true;">https://docs.djangoproject.com/en/2.0/intro/tutorial03/


--
Gonzalo Delgado

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/eee70b8a-daff-453f-bb46-b4c2769d33e9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

RE: Basic note/trello app - how to link model object IDs

Matthew Pava

You’ll want to use card.get_absolute_url.

See https://docs.djangoproject.com/en/2.0/ref/models/instances/#get-absolute-url

In your get_absolute_url, you should probably use the reverse method to use the name of a URL rather than hard-coding it in the method.  That’s the second example in that section.

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Lylio
Sent: Wednesday, February 14, 2018 9:15 AM
To: Django users
Subject: Re: Basic note/trello app - how to link model object IDs

 

Thanks for the reply Gonzalo, I really appreciate the feedback.

So, conceptually I understand how the remaining pieces of this app fit together - but could I ask for just a little more of your help as I'm struggling with coding the details of what's needed.

Let's start basic - I've got some 'cards' in my database and on one of the web pages the title of the card is presented in a list (with some CSS styling to present the list item as a rectangle):

<ul>
      
{% for card in cards.all %}
          
<li class="card">{{ card.title }}  </li>
       
{% endfor %}
</ul>


I'd like to click on one of the items in the list and open up a new page showing all the database details for that particular list item (title, description, time of creation, etc). Roughly, would I change the list items into links:

<ul>
      
{% for card in cards.all %}
          
<li class="card"><a href='card.html/get(this_object_id)>{{ card.title }}</a></li>
       {% endfor %}
</ul>

 

Then there would be a new view defined, something like

def card(request):
   
object = get(this_object_id)
    context
= {'cards': object}
   
return render(request, 'scrumbuddy/card.html', context)

 

I know this code is incorrect, but is it roughly how I should proceed? Connecting the list item URL to the card view which I don't really understand how to do.

 

Many thanks

 

Lylio

 

 

On Tuesday, 13 February 2018 14:18:25 UTC, Gonzalo Delgado wrote:

Hi Lylio,

On 12/2/18 16:20, Lylio wrote:
> 1. To click on a card so it opens up and displays the details, am I right
> to say I should create a card.html file in the templates folder for this?

It isn't necessary, but it is a good idea
What you need is to create a view that renders such template.
I suggest you write your own view function that does that, but what
you'd usually do is just use a generic view and either pass it the
template you want to use, or name the template in a way the generic view
will find it on its own.
See:
https://docs.djangoproject.com/en/2.0/topics/class-based-views/generic-display/

> 2. I'm confused about how Django keeps track of the cards in my app - I
> presume each card object has an ID in the database and I'd need this
ID in
> order to retrieve the card's details when it's clicked - but I'm
unsure of
> how to link the two. In the two pictures above, say someone clicked on
the
> 'class progression' card on the left... I'd like a new page to open up
that
> display the details for that card and allows the user to edit the info or
> completely delete the card.

Yes, in general, every Django model instance has an id (unless you
specifically tell it not to), and you can use it to create urls for the
detail view I mentioned earlier. This is a good start, but you'll later
want to add a SlugField to your Card model, and use that instead of the
id so urls look nicer.

> I'm maybe asking a bit much here - but I'm unsure of how complex these
> requirements are. It feels like it should be *fairly *straightforward.
Any
> thoughts or advice would be greatly appreciated.

I can assure you using Django for a project like yours is *very*
straightforward.
When in doubt, revisit the Django tutorial. This part is a good one for
where you're at: https://docs.djangoproject.com/en/2.0/intro/tutorial03/


--
Gonzalo Delgado

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/eee70b8a-daff-453f-bb46-b4c2769d33e9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/29197cad508a48fe881f19125a52c08f%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Basic note/trello app - how to link model object IDs

Melvyn Sopacua
In reply to this post by Lylio
On woensdag 14 februari 2018 16:14:40 CET Lylio wrote:

> I'd like to click on one of the items in the list and open up a new page
> showing all the database details for that particular list item (title,
> description, time of creation, etc). Roughly, would I change the list items
> into links:
>
> <ul>
>        {% for card in cards.all %}
>            <li class="card"><a href='card.html/get(this_object_id)>{{
> card.title }}</a></li>
>
>        {% endfor %}
> </ul>
>
>
> Then there would be a new view defined, something like
>
> def card(request):
>     object = get(this_object_id)
>     context = {'cards': object}
>     return render(request, 'scrumbuddy/card.html', context)
>

> On Tuesday, 13 February 2018 14:18:25 UTC, Gonzalo Delgado wrote:

> > I can assure you using Django for a project like yours is *very*
> > straightforward.
> > When in doubt, revisit the Django tutorial. This part is a good one for
> > where you're at: https://docs.djangoproject.com/en/2.0/intro/tutorial03/


You did not follow this advice, or you would already know how to tie the url
to the primary key of a model instance. It is spelled out there in detail.
--
Melvyn Sopacua

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/2451736.7695DCAJNb%40fritzbook.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Basic note/trello app - how to link model object IDs

Lylio
Thanks for the reply Melvyn - I'm slowly getting there!

So, I now understand how to insert the unique object reference. After creating card.html, and defining card in views, my list element URL is:

{% for card in cards.all %}
<li class="card"><a href="{% url 'card' %}/{{ card.id }}">{{ card.title }}</a> </li>
{% endfor %}
And if I click on the second card object in the list, it opens up http://127.0.0.1:8000/scrumbuddy/card/2 - hooray, progress!

Ok, so now I understand what card.id is and I use this to references the model object instances. So, I presume I need to use that ID to render the details of each card into the body block of card.html.

Would that require editing the card view? All I have at the moment is:

def card(request):
return render(request, 'scrumbuddy/card.html')

So somewhere in here I'd create a reference to card.id, and perhaps pass the id within a context variable?

Thanks again guys, it feels good to be making some progress! Really appreciate your help.

On Wednesday, 14 February 2018 16:07:32 UTC, Melvyn Sopacua wrote:
On woensdag 14 februari 2018 16:14:40 CET Lylio wrote:

> I'd like to click on one of the items in the list and open up a new page
> showing all the database details for that particular list item (title,
> description, time of creation, etc). Roughly, would I change the list items
> into links:
>
> <ul>
>        {% for card in cards.all %}
>            <li class="card"><a href='card.html/get(this_object_id)>{{
> card.title }}</a></li>
>
>        {% endfor %}
> </ul>
>
>
> Then there would be a new view defined, something like
>
> def card(request):
>     object = get(this_object_id)
>     context = {'cards': object}
>     return render(request, 'scrumbuddy/card.html', context)
>

> On Tuesday, 13 February 2018 14:18:25 UTC, Gonzalo Delgado wrote:

> > I can assure you using Django for a project like yours is *very*
> > straightforward.
> > When in doubt, revisit the Django tutorial. This part is a good one for
> > where you're at: <a href="https://docs.djangoproject.com/en/2.0/intro/tutorial03/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fdocs.djangoproject.com%2Fen%2F2.0%2Fintro%2Ftutorial03%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEJYEpqWWr8l23vhZ42lh0Zl8T5fw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fdocs.djangoproject.com%2Fen%2F2.0%2Fintro%2Ftutorial03%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEJYEpqWWr8l23vhZ42lh0Zl8T5fw&#39;;return true;">https://docs.djangoproject.com/en/2.0/intro/tutorial03/


You did not follow this advice, or you would already know how to tie the url
to the primary key of a model instance. It is spelled out there in detail.
--
Melvyn Sopacua

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b3d9d3df-b5d4-4ecb-a5bc-ecd4207c8754%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Basic note/trello app - how to link model object IDs

Lylio
In reply to this post by Lylio
Hi everyone,

I've unfortunately hit another brick wall with my Django app. I have my list of card objects, and when one of them is clicked, I'd like a new page to open that contains the details for the card that was clicked. I found out how to create a URL using {{ card.id }}:

{% for card in cards.all %}
<li class="card"><a href="{% url 'card' %}/{{ card.id }}">{{ card.title }}</a> </li>
{% endfor %}

and in views the card def is simply:

def card(request):
return render(request, 'scrumbuddy/card.html')

So, for example if I click on the third card object in the list, the URL returned is http://127.0.0.1:8000/scrumbuddy/card/3

But I'm unsure of how to populate the http://127.0.0.1:8000/scrumbuddy/card/3 page with the database info for card 3. Hopefully this screenshot can demonstrate:























On Monday, 12 February 2018 21:00:53 UTC, Lylio wrote:
Hi everyone,

I'm new to Django and currently working on a very simple app. It's basically a note app, a bit like a Trello board but aimed at creating user-story cards for software development teams (code at <a href="https://github.com/Lylio/scrumbuddy_project" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2FLylio%2Fscrumbuddy_project\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEQUgrsiyyF377LLdkC_7aaEgjfeg&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2FLylio%2Fscrumbuddy_project\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEQUgrsiyyF377LLdkC_7aaEgjfeg&#39;;return true;">https://github.com/Lylio/scrumbuddy_project).

I made a mock-up in Photoshop of how it's supposed to look:

<a href="http://i65.tinypic.com/2lv1lrk.png" style="margin-left:1em;margin-right:1em" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fi65.tinypic.com%2F2lv1lrk.png\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFz8ETrqju0wV3OYmmwGVsIVwfVhQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fi65.tinypic.com%2F2lv1lrk.png\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFz8ETrqju0wV3OYmmwGVsIVwfVhQ&#39;;return true;"> <a href="http://i64.tinypic.com/6hrthz.png" style="margin-left:1em;margin-right:1em" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fi64.tinypic.com%2F6hrthz.png\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFVJYXs2KY9fJ_8yGMHAaEoLer8QQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fi64.tinypic.com%2F6hrthz.png\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFVJYXs2KY9fJ_8yGMHAaEoLer8QQ&#39;;return true;">



I've got some basic functionality up and running - users can register and create a user-story card. When a new card is created, a title, description, time estimation are inputted. Cards are just displayed as list items in columns. I'm trying to add a button to the cards so that when it's clicked, the details of the card open up in a new and a user can edit the card info or delete it. 

A couple of noob questions:

1. To click on a card so it opens up and displays the details, am I right to say I should create a card.html file in the templates folder for this? 

2. I'm confused about how Django keeps track of the cards in my app - I presume each card object has an ID in the database and I'd need this ID in order to retrieve the card's details when it's clicked - but I'm unsure of how to link the two. In the two pictures above, say someone clicked on the 'class progression' card on the left... I'd like a new page to open up that display the details for that card and allows the user to edit the info or completely delete the card.

I'm maybe asking a bit much here - but I'm unsure of how complex these requirements are. It feels like it should be fairly straightforward. Any thoughts or advice would be greatly appreciated.

Thanks for your time

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5e39f472-d372-42b8-a5fe-ac1c3a0d75ea%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.