Mezzanine rich text field - django

how to access rich text field as a variable in django template language using in mezzanine CMS

If you are using the RichTextPage model built into Mezzanine, the tag is:
{{ page.richtextpage.content }}
If you have a custom model called CustomModel descended from Page that has a field called content that uses Mezzanine's RichTextField, the tag is:
{{ page.custommodel.content }}

Related

How to render Django model field in template form?

I'm trying to add django-faicon field in a form inside my template.
I have a form like:
from faicon.fields import FAIconField
class SomeForm(forms.Form):
icon = FAIconField()
And I add the field into template:
{{ form.icon }}
But instead a real icon field I see on webpage:
<faicon.fields.FAIconField>
What is a proper way to render icon field outside Django admin?

Django Social Auth - Referring to usersocialauth for foreign key in model

I'm using the social_django package for the first time. The project only requires authentication for the application through Facebook so I implemented the SOCIAL_AUTH_FACEBOOK method into my app, which retrieves basic info like username, first name, last name, email address. I also get the user's Facebook profile picture through SOCIAL_AUTH_FACEBOOK_EXTRA_DATA.
I want to figure out how to refer to the usersocialauth model as a parent key in my model. Right now, it's associating everything to auth_user model, which doesn't allow me to access the Facebook profile picture in the template.
Here is what I am doing at the moment:
models.py
from social_django import models as oauth_models
class Review(models.Model):
...
author = models.ForeignKey(oauth_models.USER_MODEL,
on_delete=models.CASCADE)
I am able to access the basic fields in the template through <p>{{ review.author.name }}</p>, but to see the profile picture, I have to do something like this:
{% for author in backends.associated %}
<img src="{{ author.extra_data.picture.data.url }}" alt="">
{% endfor %}
I would like to simplify this and just refer to the usersocialauth model so I can access all the data from one place in the template.
Found an easier solution.
I can keep ForeignKey relationship with the regular user model and use author.social_auth.all.0.extra_data.picture.data.url in the template.

Django 1.7 admin allow_tags issue

I am building a quiz application and I have a Question model. I want to allow the Question model to handle html tags. By using change_form.html and specifying {{ content|safe }} I was able to allow the add and edit Question pages to render the html tags. In my model I created a custom field that had allow_tags set to True which enabled me to render the Question correctly on the admin list pages. The issue now I am facing is that the breadcrumbs that appear in the admin and also the Recent Activity Widget on the dashboard shows questions and its showing away the html tags. How can I override these to handle the html tags ?

adding code for a Django admin field

I have a tinymce textarea in my django admin and I need users to be able to upload images (via AJAX) that will be linked in this textarea.
That would be accomplished by adding an "Image Upload" button (it's already working) in the top of the "Content" textarea.
What's the recommended way of doing that?
I can think on 2 solutions:
extending change_form and replacing {% for fieldset in adminform %} for the actual fields... and when it's the content field, I add this value
dynamically adding this button with javascript (find out where the content field is and add a <div> before it)
A better solution, if possible, would be to override just this specific field in the admin templates. Is that possible? Or are there better solutions?
PS: this field is not part of the DB (it just uploads one or more images, saves it to the storage and returns a link that will be included on the tinymce).
maybe you could use this
formfield_overrides from the djangodocs
if not, create a subclass of modelform and overide the form of admin with ModelAdmin.form.

Django admin checkbox with multiple select

I have a Django app. Pretty basic one at that.
In the model I have a class for items and a class for groups. The groups has a many to many for the items:
items = models.ManyToManyField(item, verbose_name="list of items", max_length=100000, blank=True)
When I add this to the admin section I would like to have a checkbox with multiple select. Is this possible. All of the solutions I have looked at don't sow it in the context of an admin page too. The Django admin page is all I need it to work on as I am not making any custom, public facing pages.
What is the easiest and most simple solution to replace the multiple select box with a multiple checkbox.
PS. I am relatively in-experienced with Django so I need to see what I need to import in the model and admin.
Thanks
If you know how to do it for a standard modelform, you know how to do it in an admin page too, as they are based on normal forms.
Just define the form as normal, then tell the admin to use it for your model:
class MyModelAdmin(admin.ModelAdmin):
form = MyFormWithTheMultipleSelect
way based on overriding admin templates
/myproject/templates/admin/myapp/mymodel/change_form.html
{% extends "admin/change_form.html" %}
{{ block.super }}
<script type='text/javascript' src='/media/js/jquery.js'></script>
<script>
$(document).ready(function(){
myselect = $("#id_M2M_FIELD_NAME");
// here you manipulating with your multiple select,
// and convert it to checkboxes, or something else.
})
</script>
{% endblock %}