i want to show some dynamic places in my web site and i follow this tutorial
geojson
models.py
class MushroomSpot(models.Model):
geom = PointField()
description = models.TextField()
picture = models.ImageField()
#property
def popupContent(self):
return '<img src="{}" /><p><{}</p>'.format(
self.picture.url,
self.description)
MushroomSpot is the ForeignKey to other models in my model
admin.py
from leaflet.admin import LeafletGeoAdmin
admin.site.register(MushroomSpot,LeafletGeoAdmin)
all work without error code.
but in my admin(administrator page) i cant to add points because dont show me the map.
administrator page
That is because you might need a widget in your form to show the map in the admin portal.
You can try django-leaflet library, they seem to support Leaflet maps form widgets.
Related
The Wagtail Form Builder documentation states:
form_page.html differs from a standard Wagtail template in that it is
passed a variable form, containing a Django Form object, in addition
to the usual page variable.
But in my current project, I need to embed a contact form (implemented as a Form Builder page) in another page. In the model for that target page, I'm using a PageChooserPanel to let an editor select the form page to embed. In other words:
class TargetPage(Page):
[...snip...]
contact_form = models.ForeignKey(
'wagtailcore.Page',
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name='+',
)
content_panels = Page.content_panels + [
[...snip...]
PageChooserPanel('contact_form', 'FormPage'),
]
My problem is in the template for the target page. I can access the attributes of the form page via page.contact_form, but since this page doesn't have a form object passed in, I can't figure out how to render my fields.
I am guessing that I need to override my target page's get_context() so that it includes the form object I need. But I can't figure out how to get that object. Can some kind soul put me on the right track?
After a night's sleep, the answer turned out to be relatively obvious. The missing link is the get_form() method of a Wagtail FormPage. I'm now using this in my TargetPage model:
def attached_form(self):
return self.contact_form.specific.get_form()
And thus, in my template, I can refer to attached_form to get my fields.
Django: 2.0.7
django-geopositions: 0.3.0
I have configured everything in SETTINGs but map does not show at admin site, only lat and long fields are shown.
My model is very simple as:
class Shop(models.Model):
name = models.CharField(max_length=100)
position = GeopositionField()
Any idea?
Please go to this link:
pull request
And edit your geoposition app as given.
Have been trying to solve an issue using Django awesome avatar. I have used the AvatarField() in my models to save the profile pic in the UserProfile model.
avatar = AvatarField(upload_to=upload_profile, width=100, height=100,default = 'profiles/profile.jpg',)
Have also used a ModelForm to render the field to a form that is shown on the templates
avatar = avatar_forms.AvatarField()
When I try to access the user profile in admin and save, it throws an error:
'ImageFieldFile' object has no attribute '__getitem__'
Also, when I select a photo on the form in template, it does not show the crop tool that am supposed to use to resize the image.
Are you trying to access the file name?
You should use something like this:
def __unicode__(self):
return unicode(self.image_location)
source: Django image field throws TypeError
I've been learning Mezzanine and currently experimenting with themes. So far, this is what I have:
-projectA <- mezzanine app
-theemeA/ <- custom theme
-admin.py
-models.py
-__init__.py
-templates/
-pages/
-about-us.html
-aboutus.html
-index.html
-base.html
-about-us.html
TheemeA is included in the project and I can see the customized index and base.html. Now I want to create a series of pages that have a common look that will go in the About US section on the site. I want this new content type to extend the base.html.
I created models.py in TheemeA; pulled from here and slightly altered for testing. I know I will need to rework some of this.
from django.db import models
from django.utils.translation import ugettext_lazy as _
from mezzanine.pages.models import Page, RichText
class AboutUs(Page, RichText):
"""
About Us Base Content Type
"""
add_toc = models.BooleanField(_("aboutus"), default=False,
help_text=_("Include a list of child links"))
class Meta:
verbose_name = _("About Us")
verbose_name_plural = _("About Us")
I've also included this new model in the admin.py for TheemeA and it shows up as a content type in the UI with a text edit field. Now I want to create a custom template that extends the model so I can customize the appearance. However, I am not able to get mezzanine to pull up my template. I've been looking at this and it's not helping.
I've tried multiple variations of about-us.html and aboutus.html in that folder and in folder called pages, but can't get it to work. Can someone please provide a bit of guidance?
Your model looks fine
admin.py should be similar to:
from .models import AboutUs,
from mezzanine.pages.admin import PageAdmin
admin.site.register(AboutUs, PageAdmin)
Create a page instance in the admin UI.
Usually a space in the title becomes - eg 'About Us' becomes 'about-us.html.
And it needs to be within the pages directory.
At the moment I'm on my way using the django-imagekit to show thumbnails in an image-heavy view of a gallery app. For this purpose I'm using the 'model-method', means I'm creating the thumbnails within the model.
Now with the comfort of the admin in mind (upload multiple picture at once) I also want to implement a multi-upload form in the admin-view. To ease things a little bit I tried to use an app I found on GitHub, django-admin-multiupload (I'm not able to link to it because of my low reputations but that's the exact name for it on GitHub).
When I only use django-imagekit, everything works fine and I get nice thumbnails, just like expected. When I only use django-admin-multiupload, everything works fine and I'm able to upload multiple images just like expected.
The problem starts when I'm using both apps at the same time. The multiupload works still fine but when I'm opening the view, and actually implementing the thumbnail (only using both and not implementing the thumbnail works fine), where the thumbnails should be shown I will get the following error:
OSError at /gallery/ - decoder jpeg not available
You can see the full error here: http://pastebin.com/gtVYEeG7
My confusion starts when starting only the single app and it works. So as far as my knowledge goes, all PIL issues could not be present.
To provide some more information: I'm using a virtualENV with the following list of packages:
pip
django
PIL
pilkit
django-imagekit
django-amdin-multiupload
To also provide some of my implementet code, here it is:
File: models.py
class Image(models.Model):
"""the model for the images"""
# the foreign key from the event
event = models.ForeignKey('Event', related_name='images',
blank=True, null=True)
# the image itself
# file = models.FileField('File', upload_to='gallery/images/')
file = models.ImageField('File', upload_to='gallery/images/')
image_thumbnail = ImageSpecField(source='file',
processors=[
ResizeToFill(300, 250)
],
format='JPEG',
options={'quality': 40})
# image title to represent it in the admin interface
image_name = models.CharField(max_length=35, default='img')
# publication date of the image
pub_date = models.DateTimeField('date published',
auto_now_add=True)
# for a better representation of the image
def __str__(self):
return self.image_name
File: admin.py
(this one is mostly as suggested in the example from the django-admin-multiupload repo, can be viewed here: https://github.com/gkuhn1/django-admin-multiupload/blob/master/example/gallery/admin.py)
from django.contrib import admin
from django.shortcuts import get_object_or_404
from gallery.models import Event, Image
from multiupload.admin import MultiUploadAdmin
# Register your models here.
# allows inline add of single images
class ImageInlineAdmin(admin.TabularInline):
model = Image
# used to define the process_uploaded_file function
# so it will not be duplicated in the Admin-Classes
class GalleryMultiuploadMixing(object):
def process_uploaded_file(self, uploaded, event, request):
image = event.images.create(file=uploaded)
return {
'url': image.file.url,
'thumbnail': image.file.url,
'id': image.id,
'name': image.image_name
}
# admin class for event model
class EventAdmin(GalleryMultiuploadMixing, MultiUploadAdmin):
inlines = [ImageInlineAdmin,]
multiupload_form = True
multiupload_list = False
def delete_file(self, pk, request):
obj = get_object_or_404(Image, pk=pk)
return obj.delete()
admin.site.register(Event, EventAdmin)
# admin class for image model
class ImageAdmin(GalleryMultiuploadMixing, MultiUploadAdmin):
multiupload_form = False
multiupload_list = True
admin.site.register(Image, ImageAdmin)
File: index.html
<td><img class="img-responsive" src="{{ image.image_thumbnail.url }}" /></td>
If there is any need for additional information please don't hesitate to ask.
Thank you in advance and I appreciate any help.
Edit: Today I tried another way and recognized that the error is only appearing to images that were uploaded with the django-admin-multiupload and not if only images are shown that were uploaded with the normal method. Maybe this could help to find a solution.
This error was mainly caused by a broken database that could be fixed by going back to an older version and reimplementing the new code. So there is no problem in django-admin-multiupload or django-imagekit.