add repr to class models and exploring relationships
This commit is contained in:
parent
936a88f264
commit
67264b3da6
11 changed files with 155 additions and 17 deletions
Binary file not shown.
Binary file not shown.
|
|
@ -14,7 +14,13 @@ class User(db.Model, UserMixin):
|
|||
email = Column('email', TEXT(), nullable=False, unique=True)
|
||||
password = Column('password', TEXT(), nullable=False)
|
||||
user_type = Column('user_type', TEXT(), nullable=False)
|
||||
donation_id = Column(INTEGER, ForeignKey('donation.id'))
|
||||
donations = db.relationship('Donation', backref='user', lazy='dynamic')
|
||||
|
||||
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"{self.id} - {self.first_name} - {self.last_name}"
|
||||
# donation_id = Column(INTEGER, ForeignKey('donation.id'))
|
||||
|
||||
def get_reset_token(self, expiration=600):
|
||||
reset_token = jwt.encode(
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
from app import db
|
||||
from app.users import users
|
||||
from app.users.models import User
|
||||
from app.campaigns.models import Campaign
|
||||
from app.main.models import Donation
|
||||
from app.users.forms import LoginForm, RegisterUserForm#, RequestResetForm, ResetPasswordForm, EditUserForm, AddUserForm
|
||||
from flask import render_template, redirect, url_for, flash, request
|
||||
from flask_login import login_required, login_user, current_user, logout_user
|
||||
|
|
@ -66,4 +68,17 @@ def register_user():
|
|||
login_user(user)
|
||||
flash('Succesfully Registered!')
|
||||
return redirect(url_for('main.homepage'))
|
||||
return render_template('register_user.html', form=form)
|
||||
return render_template('register_user.html', form=form)
|
||||
|
||||
@users.route('/test')
|
||||
def testing_route():
|
||||
user = User.query.filter_by(id=1).first()
|
||||
donation = Donation.query.filter_by(id=1).first()
|
||||
campaign = Campaign.query.filter_by(id=1).first()
|
||||
|
||||
print(campaign)
|
||||
|
||||
return render_template('test.html',
|
||||
user=user,
|
||||
donation=donation,
|
||||
campaign=campaign)
|
||||
10
app/users/templates/test.html
Normal file
10
app/users/templates/test.html
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
{% extends 'base.html' %}
|
||||
{% block title %}User Access{% endblock title %}
|
||||
{% block content %}
|
||||
{{user.first_name}}<br/>
|
||||
{{donation.amount}}<br/>
|
||||
|
||||
{% for c in campaign.donations %}
|
||||
{{c}}
|
||||
{% endfor %}
|
||||
{% endblock %}
|
||||
Loading…
Add table
Add a link
Reference in a new issue