def search_foto(request):
title = 'Поиск'
foto = OurFoto.objects.all()
form = FotoForm(request.GET)
if form.is_valid():
if form.cleaned_data['name']:
foto = foto.filter(name__icontains=form.cleaned_data['name'])
elif form.cleaned_data['text']:
foto = foto.filter(text__icontains=form.cleaned_data['text'])
elif form.cleaned_data['date_added']:
foto=foto.filter(date_added__icontains=form.cleaned_data['date_added'])
context = {'title': title, 'form': form, 'foto': foto}
return render(request, 'repository_our_fotos/search_form.html', context)
def search_foto(request):
title = 'Поиск'
if 'query' in request.GET:
query = request.GET['query']
posts = OurFoto.objects.filter(
Q(name__startswith=query) |
Q(text__startswith=query) |
Q(date_added__startswith=query)
)
return render(request, 'repository_our_fotos/search_form.html',
{'title': title, 'posts': posts, 'query': query})
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
nickname = db.Column(db.String(100), index=True, unique=True)
email = db.Column(db.String(120), index=True, unique=True)
password = db.Column(db.String(100), unique=True)
role = db.Column(db.SmallInteger, default=ROLE_USER)
posts = db.relationship('Entry', backref='users', lazy='dynamic')
about_me = db.Column(db.String(140))
last_seen = db.Column(db.DateTime())
pwdhash = db.Column(db.String(100))
avatar_hash = db.Column(db.String(32))
confirmed = db.Column(db.Boolean)