Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
Tell me how I can modify my project my_holiday, so I can add additional logic with button Add Photo to the Place for example? models.py from django.db import models class Place(models.Model): name = models.CharField(max_length=200) location = models.CharField(max_length=200) description = models.TextField() def __str__(self): return self.name class Photo(models.Model): image = models.ImageField(upload_to='place_photos/') places = models.ManyToManyField(Place, related_name='photos') def __str__(self): return f"Photo {self.id}" views.py class PhotoCreateView(CreateView): model = Photo form_class = PhotoForm template_name = 'photo_create.html' def form_valid(self, form): place_id = self.request.GET.get('place_id') place = get_object_or_404(Place, pk=place_id) form.instance.place = place return super().form_valid(form) class PhotoEditView(UpdateView): model = Photo form_class = PhotoForm template_name = 'photo_edit.html' class PhotoDetailsView(DetailView): model = Photo template_name = 'photo_details.html' photo_create.html {% extends 'base.html' %} {% block main_content %}
Add Photo
{% csrf_token %} {{ form.as_p }}
Submit
{% endblock %} photo_edit.html {% extends 'base.html' %} {% block main_content %}
Edit Photo
{% csrf_token %} {{ form.as_p }}
Update
{% endblock %} photo_details.html {% extends 'base.html' %} {% block main_content %}
Photo Details
Image:
Place: {{ object.place.location }}
{% endblock %} travelogue_view.html {% extends 'base.html' %} {% block main_content %} {% if places %}
Total places: {{ places|length }}
{% for place in places %}
{% for photo in place.photos.all %}
{% endfor %}
Location: {{ place.location }}
Category: {{ place.category }}
Details
Add Photo
{% endfor %}
{% else %}
No places yet
{% endif %} {% endblock %} urls.py from django.urls import path from .views import PhotoCreateView, PhotoEditView, PhotoDetailsView urlpatterns = [ path('photo/create/', PhotoCreateView.as_view(), name='photo_create'), path('photo/
/edit/', PhotoEditView.as_view(), name='photo_edit'), path('photo/
/', PhotoDetailsView.as_view(), name='photo_details'), ]
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)