我正在使用django-rest-auth和allauth在我的django应用程序中登录和注册.我没有为登录或注册编写任何额外的单行代码.使用emailid和提供的密码注册成功.
我不使用用户名进行身份验证,而是使用电子邮件
在我可浏览的注册api中,我得到以下内容:
除了这些字段,我想要first_name和last_name(默认的auth_user表有这些列),这样我新创建的auth_user也会设置这些字段以及电子邮件和散列密码.
我怎样才能做到这一点?这个可浏览的表单本身并不那么重要,但能够存储first_name和last_name是我主要需要的.
django django-rest-framework django-allauth django-rest-auth
那里有很多日期/日期时间选择器实现.是否有任何与Django和Crispy Forms集成的特别好,它们是如何使用的?
我希望尽量减少开发工作,最大限度地提高简单性,并利用Django本地化.
日期字段的Django/Crispy标准输出:
<input class="dateinput form-control" id="id_birth_date" name="birth_date" type="text" value="21/07/2015">
Run Code Online (Sandbox Code Playgroud)
在模型中:
birth_date = models.DateField(verbose_name='D.O.B', auto_now_add=False, auto_now=False)
Run Code Online (Sandbox Code Playgroud)
谢谢!
编辑:
档案型号:
from django.db import models
class Profile(models.Model):
birth_date = models.DateField(verbose_name='D.O.B', auto_now_add=False, auto_now=False)
Run Code Online (Sandbox Code Playgroud)
个人资料表格:
from django import forms
from profiles.models import Profile
class ProfileForm(forms.ModelForm):
class Meta:
model = Profile
birth_date = forms.DateField(
widget=forms.TextInput(
attrs={'type': 'date'}
)
)
Run Code Online (Sandbox Code Playgroud)
档案查看:
from django.shortcuts import get_object_or_404
from django.contrib.auth import get_user_model
from profiles.models import Profile
from profiles.forms import ProfileForm
User = get_user_model()
def edit(request):
profile = get_object_or_404(Profile, …Run Code Online (Sandbox Code Playgroud) Django中的多对多关系示例:
class First(models.Model):
seconds = models.ManyToManyField(Second, through='Middle')
class Middle(models.Model):
first = models.ForeignKey(First)
second = models.ForeignKey(Second)
class Second(models.Model):
Run Code Online (Sandbox Code Playgroud)
根据中间模型的文档,只有一个相关对的ManytoManyField模型包含上面示例中的模型First.它是否正确?
如果是这样,哪个模型应包含该ManytoManyField字段?使用任何一方的关系是否有任何差异取决于它在哪里ManytoManyField?
谢谢
编辑(我应该更清楚):
我对中介表感兴趣,因为我将有额外的数据存储在关系中.
当我说使用时,我并不是指定义模型,我的意思是使用关系(否则我会让Django做它的事情).
如果我想要所有与第一个相关的秒,它是否与获得与第二个相关的所有第一个完全相同,或者ManytoManyField通过引入任何额外的功能使一个方向比另一个方向更容易?
对于上下文,这是一个菜单系统.
class Menu(models.Model):
...
class Link(models.Model):
...
class MenuItem(models.Model):
menu = models.ForeignKey(Menu)
submenu = models.ForeignKey(Menu, related_name='submenu', blank=True, null=True)
link = models.ForeignKey(Link, blank=True, null=True)
position = models.IntegerField()
Run Code Online (Sandbox Code Playgroud)
我有两个想要实现的结果:
任何高级验证对我来说都是新的,因此代码示例将非常有用.
在此示例中,仅通过Django Admin添加数据
Profile包含一个PointField.我在ProfileAdmin中使用过OSMGeoAdmin,这里:
class ProfileAdmin(admin.OSMGeoAdmin):
model = Profile
Run Code Online (Sandbox Code Playgroud)
但无法弄清楚如何在内联中使用它在UserAdmin中显示.我目前的设置如下:
# User Admin, with Profile attached
class ProfileInline(admin.StackedInline):
model = Profile
can_delete = False
verbose_name_plural = 'Profile' # As only one is displayed in this view
class UserAdmin(UserAdmin):
inlines = (
ProfileInline,
)
admin.site.unregister(User)
admin.site.register(User, UserAdmin)
Run Code Online (Sandbox Code Playgroud)
在这种情况下是否可以使用类OSMGeoAdmin?
User has many Profiles
(Limit - no more than one of each profile type per user, no duplicates)
Profiles has many Attribute Values
(A user can have as many or few attribute values as they like)
Attributes belong to a category
(No overlap. This controls which attribute values a profile can have)
Run Code Online (Sandbox Code Playgroud)
我相信通过堆栈交换,您可以为一个用户提供许多配置文件,因为它们因交换站点不同而不同?在这个问题:
配置文件和属性只是在两个级别上对属性值进行分组的方法.如果没有分组(在2.之后加权需要),关系就是User hasMany Attribute Values.
为每个用户提供与其他用户相似的评级.
我希望通过控制器方法将用户发送到另一个页面.另一页需要POST数据.
通常,使用postLink()访问页面.有没有办法在控制器中使用它,也许使用redirect()?
目的是将列表视为"名称"的列表.
这是字典:
class Scripts
{
public Dictionary<int, Script> scripts = new Dictionary<int, Script>();
...
}
Run Code Online (Sandbox Code Playgroud)
这是我追求的属性'name':
class Script
{
public string name { get; set; }
...
}
Run Code Online (Sandbox Code Playgroud)
这是问题所在:
public partial class MainForm : Form
{
Scripts allScripts;
public MainForm()
{
InitializeComponent();
allScripts = new Scripts();
setupDataSources();
}
private void setupDataSources()
{
BindingSource ketchup = new BindingSource(allScripts.scripts, null);
//THIS LINE:
listBoxScripts.DisplayMember = allScripts.scripts["Key"].name.ToString();
listBoxScripts.ValueMember = "Key";
listBoxScripts.DataSource = ketchup;
}
...
}
Run Code Online (Sandbox Code Playgroud)
我只是想不出如何使这条线工作!非常感谢您的建议!
谢谢
他们似乎在做同样的事情。在功能、使用等方面有区别吗?在什么情况下应该使用一个?
谢谢
我想使用django-rest-auth轻松地在我的API 中使用django-allauth的注册和社交身份验证功能.
我也想使用django-rest-knox,因为它为每个设备提供一个令牌,而不是每个用户.
在创建用户via时django-rest-auth,它会尝试创建并返回令牌.这失败了,因为它需要用来django-rest-knox生成令牌,但我不清楚如何做到这一点.是否可以让这两个包一起工作?
谢谢!
django django-rest-framework django-allauth django-rest-auth
django ×7
algorithm ×1
c# ×1
cakephp ×1
cakephp-2.4 ×1
date ×1
datepicker ×1
datetime ×1
decorator ×1
dictionary ×1
django-admin ×1
django-orm ×1
geodjango ×1
listcontrol ×1
m2m ×1
many-to-many ×1
match ×1
menu ×1
php ×1
post ×1
python ×1
receiver ×1
redirect ×1
relationship ×1
signals ×1
similarity ×1
validation ×1
weighted ×1